Repository navigation
Expand file tree
/
Copy pathvitest.config.js
More file actions
98 lines (94 loc) · 4.18 KB
/
Copy pathvitest.config.js
File metadata and controls
98 lines (94 loc) · 4.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'path';
// Only the tests that touch the DOM run under jsdom. Booting a jsdom window
// per file cost the full suite ~680 s of summed environment time against
// ~37 s of actual test time (measured 2026-09-04, 517 files), and ~450 of
// those files are pure Node (repositories, guard, middleware, scripts). Every
// React component/hook test (.jsx/.tsx) plus the .js/.ts files below that
// reference window/document/localStorage stay on jsdom; everything else runs
// on node. A test that needs the DOM and is not matched here fails with a
// "document is not defined" — add it to DOM_TESTS, or put
// `// @vitest-environment jsdom` at the top of the file.
const DOM_TESTS = [
'__tests__/**/*.test.{jsx,tsx}',
'__tests__/unit/artifacts.repository.test.js',
'__tests__/unit/auth-invite-join.test.js',
'__tests__/unit/calibration-controller.route.test.ts',
'__tests__/unit/calibration-mining.test.js',
'__tests__/unit/cli-openclaw-install.test.js',
'__tests__/unit/containment-route.test.ts',
'__tests__/unit/context-menu-resolve.test.ts',
'__tests__/unit/discord-interactions-route.test.js',
'__tests__/unit/guard-hotpath.test.js',
'__tests__/unit/guard-risk-breakdown.test.js',
'__tests__/unit/measurement-read.test.js',
'__tests__/unit/no-silent-catch.guard.test.js',
'__tests__/unit/org-rate-limit.test.js',
'__tests__/unit/policy-contract.test.ts',
'__tests__/unit/signal-dismissals.test.js',
'__tests__/unit/trial-session-middleware.test.js',
'__tests__/unit/trial-session-routes.test.ts',
'__tests__/unit/usage-demo-fixture.test.js',
'__tests__/unit/use-list-controls.test.js',
'__tests__/unit/use-select-all-hotkey.test.ts',
'__tests__/unit/use-selection.test.ts',
'__tests__/unit/widget-pulse.logic.test.js',
];
const ROOT_TESTS = ['__tests__/**/*.test.{js,jsx,ts,tsx,mjs,cjs}'];
// Exclude Playwright specs (tests/) — they use @playwright/test, not vitest.
// Also skip the Playwright defaults, Vitest's own build outputs, and the
// CLI's node:test suite under cli/test/ (run separately by `npm test -w
// @dashclaw/cli` or `cli && npm test`).
const EXCLUDE = [
'**/node_modules/**',
'**/dist/**',
'**/.next/**',
'**/tests/**',
'**/playwright-report/**',
'**/test-results/**',
'cli/test/**',
// mcp-server's TS package suite runs separately via `cd mcp-server &&
// npm run verify` (its own vitest); lib/ and dist/ are compiled output.
'mcp-server/test/**',
'mcp-server/lib/**',
'mcp-server/dist/**',
'plans/**',
// Git worktrees may hold sibling-branch copies of the test suite with
// their own divergent state; vitest should never walk into them. Cover
// both a top-level `.worktrees/` and Claude Code's `.claude/worktrees/`.
'**/.worktrees/**',
'**/worktrees/**',
];
export default defineConfig({
plugins: [react()],
test: {
// Project arrays replace (not merge) the root value, so the node project
// restates EXCLUDE alongside the DOM set it hands to jsdom.
projects: [
{ extends: true, test: { name: 'dom', environment: 'jsdom', include: DOM_TESTS, exclude: EXCLUDE } },
{ extends: true, test: { name: 'node', environment: 'node', include: ROOT_TESTS, exclude: [...EXCLUDE, ...DOM_TESTS] } },
],
globals: true,
// Automatically reset env-var mutations between tests so `vi.stubEnv`
// or direct `process.env.X = ...` writes in one test do not leak into
// the next. Many existing tests set env vars without a matching
// afterEach restore — `unstubEnvs: true` provides the guardrail while
// those test files are gradually migrated to vi.stubEnv.
unstubEnvs: true,
// Exclude Playwright specs (tests/) — they use @playwright/test, not vitest.
// Also skip the Playwright defaults, Vitest's own build outputs, and the
// CLI's node:test suite under cli/test/ (run separately by `npm test -w
// @dashclaw/cli` or `cli && npm test`).
exclude: EXCLUDE,
},
resolve: {
alias: {
'@': path.resolve(__dirname, './app'),
'openclaw/plugin-sdk/plugin-entry': path.resolve(
__dirname,
'./__tests__/fixtures/openclaw-plugin-entry.js'
),
},
},
});