-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvitest.config.mjs
More file actions
61 lines (58 loc) · 2.81 KB
/
Copy pathvitest.config.mjs
File metadata and controls
61 lines (58 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Vitest config for the volto-hydra addon's unit tests.
//
// Why vitest, not jest? Volto 19 itself migrated to vitest for its own
// tests; the legacy razzle-jest path is unmaintained (razzle's
// createJestConfig was written for Jest 26 and breaks under Jest 30 with
// a chain of version-mismatched deep deps: jest-environment-jsdom@26
// vs @jest/transform@30, babel-jest@26 vs @jest/transform@30, etc.).
// Aligning all of them via pnpm.overrides would be brittle. Vitest is the
// supported direction; using it here lets us share Volto's catalog
// version pin and skip the legacy ecosystem entirely.
//
// hydra-js stays on its own jest setup (it has ESM-specific needs);
// this config only covers volto-hydra's addon tests.
import { defineConfig } from 'vitest/config';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Resolve @plone/* imports to their workspace source directories. Razzle's
// webpack does this implicitly via the customization-paths machinery, but
// vite needs explicit aliases for subpath imports like
// `@plone/volto-slate/utils` because the workspace packages don't declare
// an `exports` map.
const ploneAliases = {
'@plone/volto-slate': path.resolve(__dirname, 'core/packages/volto-slate/src'),
'@plone/volto': path.resolve(__dirname, 'core/packages/volto/src'),
'@plone/components': path.resolve(__dirname, 'core/packages/components/src'),
'@plone/registry': path.resolve(__dirname, 'core/packages/registry/src'),
};
export default defineConfig({
resolve: {
alias: ploneAliases,
},
test: {
globals: true,
environment: 'jsdom',
include: [
'packages/volto-hydra/**/*.{test,spec}.{js,jsx,ts,tsx}',
// The pure data helpers (buildQuerystringSearchBody etc.) — server-safe,
// no DOM, so their unit tests live alongside them here.
'packages/helpers/**/*.{test,spec}.{js,jsx,ts,tsx}',
],
// hydra-js has its own jest harness; covered by `cd packages/hydra-js && pnpm test` in CI.
exclude: ['**/node_modules/**', 'packages/hydra-js/**'],
// Reuse Volto's setup files via the workspace. These initialise the
// shared config registry (settings.slate.extensions etc.) and DOM
// shims (matchMedia, IntersectionObserver) so tests don't have to
// bootstrap Volto themselves.
setupFiles: [
path.resolve(__dirname, 'core/packages/volto/test-setup-globals.js'),
path.resolve(__dirname, 'core/packages/volto/test-setup-config.jsx'),
// Hydra-specific: invoke volto-slate's applyConfig so the slate
// plugin chain (Markdown etc.) populates settings.slate.extensions.
// Volto's setup files initialise the bare config registry but don't
// invoke addon applyConfig chains.
path.resolve(__dirname, 'vitest-setup-hydra.js'),
],
},
});