Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
117 lines (113 loc) · 4.18 KB
/
Copy pathvitest.config.ts
File metadata and controls
117 lines (113 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { availableParallelism, freemem } from 'node:os'
import { playwright } from '@vitest/browser-playwright'
import { defineConfig, mergeConfig } from 'vitest/config'
import {
budgetsElsewhere,
buildTests,
buildsElsewhere,
inBrowser,
perfTests,
playwrightUnitElsewhere,
playwrightUnitTests,
shared,
} from './vitest.shared.js'
const everywhere = [
'packages/*/test/**/*.test.ts',
'examples/*/test/**/*.test.ts',
'examples/foldkit/*/test/**/*.test.ts',
'scripts/test/**/*.test.ts',
]
const browserTests = [
'packages/*/test/**/*.browser.test.ts',
'examples/*/test/**/*.browser.test.ts',
'examples/foldkit/*/test/**/*.browser.test.ts',
]
/**
* Tests of a coarse pointer, on a page that is a touch screen from the start.
* Touch emulation cannot be undone in a page: on Linux, Chromium turned off
* again reports `pointer: none`, and every later file in that page lost its
* fine pointer.
*/
const touchTests = browserTests.map(pattern => pattern.replace('.browser.', '.touch.browser.'))
const browser = (contextOptions: { readonly hasTouch: boolean }) => ({
enabled: true,
headless: true,
provider: playwright({
contextOptions,
// Linux CI containers cap `/dev/shm` at 64 MB; without `--disable-dev-shm-usage`,
// Chromium tabs crash mid-shard with `VITEST_BROWSER_CONNECTION_CLOSED`.
launchOptions: { args: ['--disable-dev-shm-usage', '--disable-gpu'] },
}),
instances: [{ browser: 'chromium' as const, viewport: { width: 1440, height: 900 } }],
})
/**
* Workers by the memory free when the run starts, not by cores alone. On a
* 16-core machine with 4 GiB free (2026-10-12), a worker per core less one
* ran out of memory and was killed; at 0.75 GiB each (5 workers), the whole
* suite peaked 5.1 GiB over its start, Chromium included, and finished in
* seven minutes. `--maxWorkers` still wins.
*/
const maxWorkers = Math.max(
1,
Math.min(availableParallelism() - 1, Math.floor(freemem() / (0.75 * 2 ** 30))),
)
export default defineConfig({
test: {
maxWorkers,
projects: [
mergeConfig(shared, {
test: {
name: 'unit',
include: everywhere,
exclude: [
...browserTests,
...(budgetsElsewhere ? perfTests.unit : []),
...(buildsElsewhere ? buildTests : []),
...(playwrightUnitElsewhere ? playwrightUnitTests : []),
'**/node_modules/**',
],
},
}),
// What jsdom cannot check: layout, focus, the caret. Headless Chromium,
// at a desktop size, so a full-screen layout is the one users see.
mergeConfig(inBrowser, {
test: {
name: 'browser',
include: browserTests,
exclude: [...touchTests, '**/node_modules/**'],
// One retry on shared CI runners for single-frame/Chromium hiccups; 0 locally.
retry: process.env.CI !== undefined ? 1 : 0,
// The benchmarks measure Node; several cannot load in a page at all.
benchmark: { include: [] },
browser: browser({ hasTouch: false }),
},
}),
// The upstream foldkit-domains copy keeps its own test setup (happy-dom,
// Foldkit's Vitest setup, tests beside the source), as upstream runs it.
// Given by path, it took Vitest's default workers, not `maxWorkers`, and
// Vitest refuses projects in one group whose workers differ: a local run
// whose free memory lowered `maxWorkers` failed before any test ran.
{
extends: './examples/foldkit/domains/vitest.config.ts',
// Its slowest Scene test (the mobile TLD sheet, 0.9s alone) ran past Vitest's 5s in a
// CI shard that also held the browser and workerd tests; the limit here is the unit
// project's own headroom, not upstream's default.
test: {
name: 'foldkit-domains',
root: './examples/foldkit/domains',
maxWorkers,
testTimeout: 20_000,
},
},
mergeConfig(inBrowser, {
test: {
name: 'browser-touch',
include: touchTests,
retry: process.env.CI !== undefined ? 1 : 0,
benchmark: { include: [] },
browser: browser({ hasTouch: true }),
},
}),
],
},
})