forked from promptfoo/promptfoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
70 lines (61 loc) · 2.24 KB
/
vitest.config.ts
File metadata and controls
70 lines (61 loc) · 2.24 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
import os from 'os';
import { defineConfig } from 'vitest/config';
const cpuCount = os.cpus().length;
// Use most cores but leave 2 for system/main process
const maxForks = Math.max(cpuCount - 2, 4);
export default defineConfig({
test: {
deps: {
interopDefault: true,
},
environment: 'node',
exclude: ['**/*.integration.test.ts', '**/node_modules/**', 'test/smoke/**'],
globals: false,
include: ['test/**/*.test.ts', 'test/**/*.test.tsx'],
root: '.',
setupFiles: ['./vitest.setup.ts'],
// Run tests in random order to catch test isolation issues early.
// Tests should not depend on execution order or shared state.
// Override with --sequence.shuffle=false when debugging specific failures.
sequence: {
shuffle: true,
},
// Use forks (child processes) instead of threads for better memory isolation.
// When a fork dies or is recycled, the OS fully reclaims its memory.
// Worker threads share memory with the main process and can leak.
pool: 'forks',
// Vitest 4: poolOptions are now top-level
maxWorkers: maxForks,
isolate: true, // Each test file gets a clean environment
execArgv: [
'--max-old-space-size=3072', // 3GB per worker - generous but bounded
],
// Timeouts to prevent stuck tests from hanging forever
testTimeout: 30_000, // 30s per test
hookTimeout: 30_000, // 30s for beforeAll/afterAll hooks
teardownTimeout: 10_000, // 10s for cleanup
// Limit concurrent tests within each worker to prevent memory spikes
maxConcurrency: 10,
// Fail fast on first error in CI, continue locally for full picture
bail: process.env.CI ? 1 : 0,
// Coverage configuration
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
reportsDirectory: './coverage',
include: ['src/**/*.ts', 'src/**/*.tsx'],
exclude: [
'src/**/*.d.ts',
'src/**/*.test.ts',
'src/**/*.test.tsx',
'src/__mocks__/**',
'src/app/**', // Frontend workspace has its own coverage
'src/entrypoint.ts',
'src/main.ts',
'src/migrate.ts',
],
// @ts-expect-error - 'all' is valid in Vitest v8 coverage but types are incomplete
all: true,
},
},
});