Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
250 lines (243 loc) · 10.9 KB
/
Copy pathvitest.config.ts
File metadata and controls
250 lines (243 loc) · 10.9 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
// vitest.config.ts
// Root config with two workspace projects: unit (node) and dom (jsdom).
// Vitest 4 uses inline `projects` array instead of vitest.workspace.ts.
import { defineConfig } from 'vitest/config';
import react from '@vitejs/plugin-react';
import path from 'path';
// Shared exclude patterns — must match both projects
const sharedExclude = [
'e2e/**',
'node_modules/**',
'**/*.visual.tsx',
'**/*.bench.ts',
'.worktrees/**',
'**/__kernel-tests__/**',
];
// DOM project claims these globs — everything else goes to unit.
// Listed here so the unit project can exclude them to prevent double-counting.
const domIncludes = [
// All .test.tsx files are React component tests and need jsdom.
'src/**/*.test.tsx',
'src/shared/components/**/*.test.{ts,tsx}',
// `src/shared/help/` tests live directly under the prefix with no
// sub-directory, which not every glob implementation matches via `**/`.
// Both patterns guarantee the dispatcher test lands in jsdom env.
'src/shared/help/*.test.{ts,tsx}',
'src/shared/help/**/*.test.{ts,tsx}',
'src/shared/hooks/**/*.test.{ts,tsx}',
'src/shared/webgl/**/*.test.{ts,tsx}',
'src/features/**/components/**/*.test.{ts,tsx}',
'src/features/**/hooks/**/*.test.{ts,tsx}',
'src/design-system/**/*.test.{ts,tsx}',
'src/shell/**/*.test.{ts,tsx}',
];
// Heavy brepjs/OpenCascade WASM generator tests. Isolated into their own
// project (same node env/setup as `unit`) so CI can run them on dedicated
// runners — Vitest shards by hashing the file path, not by duration, so left
// in `unit` they cluster onto one shard and dominate wall time. The `unit`
// project excludes these to avoid double-counting; the full local/coverage run
// still executes all three projects.
const generatorIncludes = ['src/features/generation/worker/generators/**/*.test.ts'];
// The costliest generator files. PR shards skip them; main runs them, so the
// release gate is unchanged and only PR-time feedback moves.
const heavyGeneratorIncludes = [
'src/features/generation/worker/generators/binGenerator.export.kumikoPatterns.test.ts',
'src/features/generation/worker/generators/binGenerator.scenario.kumikoPatterns.test.ts',
'src/features/generation/worker/generators/binGenerator.export.dividerPatterns.test.ts',
'src/features/generation/worker/generators/binGenerator.scenario.dividerPatterns.test.ts',
'src/features/generation/worker/generators/binGenerator.export.kumikoWrapping.test.ts',
'src/features/generation/worker/generators/binGenerator.export.permutationMatrix.test.ts',
'src/features/generation/worker/generators/binGenerator.scenario.split-range.test.ts',
'src/features/generation/worker/generators/baseplateGenerator.scenario.outline.test.ts',
'src/features/generation/worker/generators/hingeSwing.scenario.test.ts',
'src/features/generation/worker/generators/slideLidSeating.scenario.test.ts',
'src/features/generation/worker/generators/fitTestSlice.scenario.test.ts',
'src/features/generation/worker/generators/labelPlateBuilder.test.ts',
];
const GENERATOR_TEST_TIMEOUT_MS = 120_000;
const GENERATOR_HOOK_TIMEOUT_MS = 120_000;
// Tests that need a real Redis rather than a hand-rolled ioredis mock — a Lua
// script's behaviour cannot be asserted against a mock. Isolated into their own
// project so the default `unit` run stays dependency-free; CI supplies
// REDIS_TEST_URL from a service container.
const integrationIncludes = ['api/**/*.integration.test.ts'];
export default defineConfig({
plugins: [react()],
// Build-time version constants (provided by versionPlugin in the real build).
// Defined here so PWA modules that reference them are testable under Vitest.
define: {
__APP_VERSION__: JSON.stringify('0.0.0-test'),
__GIT_SHA__: JSON.stringify('test-sha'),
__BUILD_TIME__: JSON.stringify('1970-01-01T00:00:00.000Z'),
},
test: {
globals: true,
testTimeout: 30000,
// Kernel-specific snapshot files: scenario triangle counts depend on the
// active kernel's tessellation density, so route each non-default kernel to
// its own `.<kernel>.snap`. The default (occt-wasm) keeps the plain `.snap`
// files, so existing baselines are untouched; BREPJS_KERNEL=brepkit
// reads/writes `.brepkit.snap`. Without this a single shared snapshot could
// only ever match one kernel. (resolveSnapshotPath is a root-only vitest
// option — it cannot live in a project config.)
resolveSnapshotPath: (testPath: string, snapExtension: string): string => {
const raw = process.env.BREPJS_KERNEL ?? '';
const kernel = raw === 'wasm' ? 'brepkit' : raw;
const suffix = kernel && kernel !== 'occt-wasm' ? `.${kernel}` : '';
return path.join(
path.dirname(testPath),
'__snapshots__',
`${path.basename(testPath)}${suffix}${snapExtension}`
);
},
pool: 'threads',
maxWorkers: process.env.CI ? '100%' : '75%',
// Coverage instrumentation slows tight loops several times over; wall-clock
// limits read this through `timeLimitMs` (src/test/timeLimit.ts).
env: { VITEST_COVERAGE_RUN: process.argv.includes('--coverage') ? '1' : '' },
coverage: {
provider: 'v8',
reporter: ['text', 'text-summary', 'html'],
exclude: [
'node_modules/**',
'e2e/**',
'src/test/**',
'**/*.test.{ts,tsx}',
'**/*.visual.tsx',
'**/*.d.ts',
'**/*.config.*',
'**/types.ts',
'**/index.ts',
// api/ is NOT excluded. Its tests already run in the unit project, so
// excluding it only suppressed the report: a well-covered, security-
// sensitive surface (auth, moderation, quotas, rate limits) sat under
// no threshold at all, and a regression there registered as nothing.
'src/shell/Collab/**',
'src/shared/hooks/usePresence.ts',
// Playwright drivers for the docs shots and tip clips. They run only
// against a live app. A unit test loads them just to check the shot
// registry, so counting them would make each docs page lower coverage.
'scripts/docs-capture/**',
'scripts/feature-tips/**',
],
// Set just under what the suite actually achieves, leaving room for
// ordinary churn. Thresholds far below reality let a real regression
// land without tripping one.
thresholds: {
lines: 86,
branches: 78,
functions: 83,
statements: 84,
},
},
projects: [
{
extends: true,
test: {
name: 'unit',
environment: 'node',
setupFiles: ['./src/test/setup.ts'],
include: [
'src/**/*.test.ts',
'api/**/*.test.ts',
'scripts/**/*.test.ts',
'packages/**/*.test.ts',
],
exclude: [...sharedExclude, ...domIncludes, ...generatorIncludes, ...integrationIncludes],
},
},
{
extends: true,
test: {
name: 'dom',
environment: 'jsdom',
setupFiles: ['./src/test/setup.ts', './src/test/setup-dom.ts'],
include: domIncludes,
exclude: sharedExclude,
},
},
{
extends: true,
test: {
name: 'generators',
environment: 'node',
setupFiles: ['./src/test/setup.ts'],
include: generatorIncludes,
exclude: [...sharedExclude, ...heavyGeneratorIncludes],
// The root 30s is calibrated for pure-JS tests that finish in
// milliseconds. Everything here drives real OCCT booleans, and 1423
// of the project's 1748 `it`s inherit that figure rather than
// declaring their own, so the cap the heavy tests actually run under
// was set by a different workload's needs. The slowest of them cost
// ~12s, 40% of the budget, and a shared runner spends that margin
// (#3537): the test that timed out differed every attempt because it
// was only ever whichever inherited test was slowest that run. 120s
// is the tier the deliberately-annotated heavy files already use.
//
// This is a liveness bound, not a performance budget, and it was never
// serving as one: a timeout only fires on the slowest test of whatever
// run trips it. `tessellation.perf` is the one file here that enforces
// timing, via `toBeLessThan(MAX_MS_*)` against `performance.now()`, and
// the cap above does not touch it. The `.perf` files under
// `__kernel-tests__` only record measurements, and `sharedExclude` keeps
// that directory out of this project regardless. A wedged kernel stays
// bounded by the job's `timeout-minutes`.
testTimeout: GENERATOR_TEST_TIMEOUT_MS,
// Separate knob with its own, tighter default (10s), and every file
// here boots the WASM kernel via `initTestKernel()` in `beforeAll`.
// 175 of 199 hooks were given an explicit raise by hand, which is why
// `}, 30000)` on a hook is load-bearing rather than a restatement of
// the default the way the `it`-level ones are. This covers the 24 that
// were never given one.
hookTimeout: GENERATOR_HOOK_TIMEOUT_MS,
benchmark: {
include: ['**/*.bench.ts'],
},
},
},
{
extends: true,
test: {
name: 'generators-heavy',
environment: 'node',
setupFiles: ['./src/test/setup.ts'],
include: heavyGeneratorIncludes,
exclude: sharedExclude,
testTimeout: GENERATOR_TEST_TIMEOUT_MS,
hookTimeout: GENERATOR_HOOK_TIMEOUT_MS,
},
},
{
extends: true,
test: {
name: 'integration',
environment: 'node',
setupFiles: ['./src/test/setup.ts'],
include: integrationIncludes,
exclude: sharedExclude,
// Every integration file FLUSHDBs the same Redis in beforeEach, so
// running them in parallel lets one file wipe another's state
// mid-test. That surfaced as unrelated-looking flakes: a rate-limit
// window losing entries, a like toggle finding its sets empty.
// Serialising the files is the fix; they are fast and few.
fileParallelism: false,
},
},
],
// Vitest 5 gives every project a benchmark twin. Discovery is off here so
// only the generators project below (the one with the WASM kernel and the
// 120s budget) runs the bench files, instead of all five projects re-running them.
benchmark: {
include: [],
exclude: ['node_modules/**', '.worktrees/**'],
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
'@gridfinity/branded-types': path.resolve(__dirname, 'packages/branded-types/src/index.ts'),
'virtual:pwa-register/react': path.resolve(__dirname, 'src/test/mocks/pwa-register.ts'),
},
dedupe: ['three'],
},
});