-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvitest.config.ts
More file actions
168 lines (156 loc) · 5.76 KB
/
vitest.config.ts
File metadata and controls
168 lines (156 loc) · 5.76 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import path from 'node:path';
import { defineConfig } from 'vitest/config';
// Use fewer threads in CI to reduce memory pressure; use more locally for speed.
const isCI = process.env.CI === 'true' || process.env.CI === '1';
const resolve = {
// Order matters: web-side prefixes must come before the catch-all `@`.
alias: [
{
find: /^@\/components\/(.*)/,
replacement: path.resolve(__dirname, './web/src/components/$1'),
},
{ find: /^@\/lib\/(.*)/, replacement: path.resolve(__dirname, './web/src/lib/$1') },
{ find: /^@\/hooks\/(.*)/, replacement: path.resolve(__dirname, './web/src/hooks/$1') },
{ find: '@', replacement: path.resolve(__dirname, './src') },
{ find: 'react', replacement: path.resolve(__dirname, 'node_modules/react') },
{ find: 'react-dom', replacement: path.resolve(__dirname, 'node_modules/react-dom') },
],
};
// Shared settings inherited by every unit project
const sharedTest = {
globals: true,
environment: 'node' as const,
clearMocks: true,
unstubEnvs: true,
setupFiles: ['./tests/setup.ts'],
// ── Dependency resolution ─────────────────────────────────────────────────
// Explicit moduleDirectories reduces file-system traversal during collect.
// Cache note: in CI, cache node_modules/.vitest between runs for speed.
deps: {
moduleDirectories: ['node_modules'],
},
// ── Fork pool settings ───────────────────────────────────────────────────
// maxForks: 4 in CI (lower memory pressure), 8 locally (12 CPUs available)
// minForks: 2 avoids cold-start overhead on worker spin-up
pool: 'forks' as const,
poolOptions: {
forks: {
maxForks: isCI ? 4 : 8,
minForks: 2,
},
},
};
export default defineConfig({
test: {
globals: true,
environment: 'node',
clearMocks: true,
unstubEnvs: true,
coverage: {
provider: 'v8',
reporter: ['text', 'lcov', 'html'],
include: ['src/**/*.ts'],
exclude: ['src/**/*.test.ts', 'src/types/**', 'src/index.ts'],
thresholds: {
lines: 80,
functions: 80,
branches: 75,
statements: 80,
},
},
// ── Workspace projects (Vitest v3 preferred API) ──────────────────────
// Split unit tests into 4 domain projects to reduce per-worker module
// graph size and parallelize the collect phase.
projects: [
// ── Unit: Triggers ──────────────────────────────────────────────
// ~37 files — heaviest mocks, many files mock trigger-check.js
{
test: {
name: 'unit-triggers',
include: ['tests/unit/triggers/**/*.test.ts'],
...sharedTest,
},
resolve,
},
// ── Unit: Backends ──────────────────────────────────────────────
// ~25 files — complex mock setups (adapter.test.ts has 18 vi.mock calls)
{
test: {
name: 'unit-backends',
include: ['tests/unit/backends/**/*.test.ts'],
...sharedTest,
},
resolve,
},
// ── Unit: API / Router ──────────────────────────────────────────
// ~50 files — API and router tests
{
test: {
name: 'unit-api',
include: ['tests/unit/api/**/*.test.ts', 'tests/unit/router/**/*.test.ts'],
...sharedTest,
},
resolve,
},
// ── Unit: Core ──────────────────────────────────────────────────
// ~159 files — agents, gadgets, config, db, utils, cli, pm, github,
// jira, trello, web, webhook, queue, and top-level unit tests.
// isolate: false skips per-file module re-evaluation, reducing the
// collect phase overhead. Safe here because these tests use simple
// mocks with no inter-test shared state. Files that use
// vi.useFakeTimers() all call vi.useRealTimers() in afterEach/afterAll.
{
test: {
name: 'unit-core',
include: [
'tests/unit/agents/**/*.test.ts',
'tests/unit/gadgets/**/*.test.ts',
'tests/unit/config/**/*.test.ts',
'tests/unit/db/**/*.test.ts',
'tests/unit/utils/**/*.test.ts',
'tests/unit/cli/**/*.test.ts',
'tests/unit/pm/**/*.test.ts',
'tests/unit/integrations/**/*.test.ts',
'tests/unit/github/**/*.test.ts',
'tests/unit/jira/**/*.test.ts',
'tests/unit/linear/**/*.test.ts',
'tests/unit/trello/**/*.test.ts',
'tests/unit/web/**/*.test.ts',
'tests/unit/webhook/**/*.test.ts',
'tests/unit/queue/**/*.test.ts',
'tests/unit/integration-helpers/**/*.test.ts',
'tests/unit/tools/**/*.test.ts',
'tests/unit/openrouter/**/*.test.ts',
'tests/unit/sentry/**/*.test.ts',
'tests/unit/*.test.ts',
],
...sharedTest,
isolate: false,
},
resolve,
},
// ── Integration ─────────────────────────────────────────────────
// Kept on forks + singleFork (requires real DB, no parallel workers)
{
test: {
name: 'integration',
include: ['tests/integration/**/*.test.ts'],
setupFiles: ['./tests/integration/setup.ts'],
globals: true,
environment: 'node',
clearMocks: true,
unstubEnvs: true,
testTimeout: 30_000,
hookTimeout: 30_000,
pool: 'forks',
poolOptions: { forks: { singleFork: true } },
deps: {
moduleDirectories: ['node_modules'],
},
},
resolve,
},
],
},
resolve,
});