Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
713 lines (699 loc) · 28.2 KB
/
Copy pathvite.config.ts
File metadata and controls
713 lines (699 loc) · 28.2 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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
import { globSync } from 'node:fs';
import { availableParallelism } from 'node:os';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite-plus';
import { integrationTestDirs, listIntegrationTestFiles } from './test/integration-files.ts';
import { SuiteSequencer } from './test/sequencer.ts';
import { chunkTestFiles } from './test/test-chunks.ts';
const maxWorkers = process.env.CI ? 2 : Math.max(2, Math.floor(availableParallelism() * 0.75));
const apiTimezoneTests = [
'platform/packages/api/test/integration/api-delete-accounting.test.ts',
'platform/packages/api/test/integration/email-connections.test.ts',
];
// Platform unit files that start PGlite. Add new PGlite unit files here.
const pgliteUnitTests = [
'platform/packages/api/test/unit/admin-upgrade-compatibility.test.ts',
'platform/packages/api/test/unit/email-migration.test.ts',
'platform/packages/api/test/unit/email-shared-recipient-migration.test.ts',
'platform/packages/api/test/unit/github-authority-constraints-migration.test.ts',
'platform/packages/api/test/unit/github-authority-migration.test.ts',
];
const cliUnitTests = [
'packages/void/test/unit/cf-*.test.ts',
'packages/void/test/unit/cloudflare-operation-process*.test.ts',
'packages/void/test/unit/provision-*.test.ts',
'packages/void/test/unit/deploy-drift.test.ts',
];
// SDK unit files that start PGlite. Add new PGlite unit files here.
const sdkPgliteUnitTests = [
'packages/void/test/unit/auth-migrations.test.ts',
'packages/void/test/unit/db-export-roundtrip.test.ts',
'packages/void/test/unit/db-request-pool.test.ts',
'packages/void/test/unit/db-reset-pg.test.ts',
'packages/void/test/unit/platform-database-lock.test.ts',
'packages/void/test/unit/platform-database-migrations.test.ts',
'packages/void/test/unit/runner-pg.test.ts',
'packages/void/test/unit/sveltekit-worker-build.test.ts',
'packages/void/test/unit/wrapper.test.ts',
];
// Vitest forwards a FILTERED env to test workers — in CI only VOID_E2E_CF_TOKEN survives, while
// VOID_E2E_CF_ACCOUNT_ID and VOID_E2E_NAMESPACE are dropped. The gated live Cloudflare deploy e2e
// (packages/void/test/e2e/cloudflare-deploy-live.test.ts) needs all three, so forward them into the
// core-markdown workers explicitly from this main config process (which has the runner's step env).
// Absent credentials become empty strings so ordinary test runs skip the live suite.
const e2eWorkerEnv = {
VOID_TEST_BROWSER: process.env.VOID_TEST_BROWSER ?? 'chromium',
VOID_E2E_CF_TOKEN: process.env.VOID_E2E_CF_TOKEN ?? '',
VOID_E2E_CF_ACCOUNT_ID: process.env.VOID_E2E_CF_ACCOUNT_ID ?? '',
VOID_E2E_NAMESPACE: process.env.VOID_E2E_NAMESPACE ?? '',
};
// Windows CI runners are 2-3x slower for builds and server startup.
const ciTimeoutScale = process.platform === 'win32' ? 3 : 1;
const testTimeout = 120_000 * ciTimeoutScale;
const hookTimeout = 120_000 * ciTimeoutScale;
const platformAlias = {
'void/_sandbox-container': fileURLToPath(
new URL('packages/void/src/runtime/sandbox/container.ts', import.meta.url),
),
'void:sandbox-controller-source': fileURLToPath(
new URL('platform/packages/api/test/__mocks__/sandbox-controller-source.ts', import.meta.url),
),
// cloudflare:workers is only available in the Workers runtime.
'cloudflare:workers': fileURLToPath(
new URL('platform/packages/api/test/__mocks__/cloudflare-workers.ts', import.meta.url),
),
// cloudflare:email is a workerd built-in with no npm shim, so any module
// importing it is unloadable in the plain-node unit runner.
'cloudflare:email': fileURLToPath(
new URL('platform/packages/api/test/__mocks__/cloudflare-email.ts', import.meta.url),
),
'vite-plus/test': fileURLToPath(
new URL('node_modules/vite-plus/dist/test/index.js', import.meta.url),
),
};
// Each Vitest project belongs to exactly one cached test group of `vp run test`. The check at
// the end of this file fails when a project is in no group, so a new project cannot be left out.
const testGroups = {
platform: [
'platform-unit',
'platform-unit-pglite',
'platform-api-integration',
'platform-api-integration-threads',
],
unit: ['unit', 'unit-pglite', 'cli-unit'],
integration: ['parallel-integration'],
};
// The files a cached test task reads are its inputs. Two trees are left out: Node's compile
// cache, which every run rewrites, and the temporary playground copies. A copy is made from
// tracked files, and some frameworks list the directory that holds the copies of other tests.
const testGroupInput = [{ auto: true }, '!node_modules/.cache/**', '!playground-local/**'];
function testGroupCommand(group: keyof typeof testGroups): string {
return `vp test run ${testGroups[group].map((name) => `--project ${name}`).join(' ')}`;
}
// The integration group runs one cached task per test file. Each task records the files its test
// reads, so a change reruns only the files that depend on it and the others are replayed.
const e2eEnvNames = ['VOID_E2E_CF_TOKEN', 'VOID_E2E_CF_ACCOUNT_ID', 'VOID_E2E_NAMESPACE'];
const integrationFileTasks = Object.fromEntries(
listIntegrationTestFiles(import.meta.dirname).map((file) => [
`test:integration:${file}`,
{
command: `vp test run --project parallel-integration ${file}`,
cache: { input: testGroupInput, output: [], untrackedEnv: e2eEnvNames },
},
]),
);
// The unit and platform groups run as cached chunks of related files. One Vitest run per file
// would cost more than the tests themselves, so files are chunked by directory instead.
//
// A large directory of unit tests is divided further by file name: a source change then reruns
// the chunks that import it. The platform group is not divided, because every API integration
// test loads the whole API and an API change reruns all of them anyway.
//
// Chunks run side by side. A chunk gets workers for its size, and at least two: most are small.
const unitTestGlobs = ['docs/test/unit/**/*.test.ts', 'packages/*/test/unit/**/*.test.ts'];
const platformTestGlobs = ['platform/packages/*/test/**/*.test.ts'];
const chunkConcurrency = Math.max(2, maxWorkers - 1);
function chunkTasks(group: 'unit' | 'platform', globs: Array<string>) {
const files = globSync(globs, { cwd: import.meta.dirname }).map((file) =>
file.replaceAll('\\', '/'),
);
const divideLargeDirectories = group === 'unit';
return Object.fromEntries(
[...chunkTestFiles(files, { divideLargeDirectories })].map(([chunk, chunkFiles]) => {
const workers = divideLargeDirectories
? 2
: Math.min(maxWorkers, Math.max(2, Math.ceil(chunkFiles.length / 12)));
return [
`test:${group}:${chunk}`,
{
command: `${testGroupCommand(group)} --maxWorkers ${workers} ${chunkFiles.join(' ')}`,
cache: { input: testGroupInput, output: [] },
},
];
}),
);
}
const unitChunkTasks = chunkTasks('unit', unitTestGlobs);
const platformChunkTasks = chunkTasks('platform', platformTestGlobs);
const config = defineConfig({
run: {
tasks: {
'build:all': {
command:
"vp run build && vp run --filter './platform/packages/**' build && vp run --filter './playground/**' --parallel build",
},
'lint:platform': {
command: 'vp lint platform --type-aware --tsconfig platform/tsconfig.json',
},
// One cached task per test group, so `test:all` replays a group whose inputs did not change.
// Test output is not restored on a hit.
...platformChunkTasks,
'test:platform:chunks': {
command: 'node test/check-test-tasks.mjs platform',
dependsOn: Object.keys(platformChunkTasks),
},
'test:group:platform': {
command: `vp run --concurrency-limit ${chunkConcurrency} test:platform:chunks`,
},
...unitChunkTasks,
'test:unit:chunks': {
command: 'node test/check-test-tasks.mjs unit',
dependsOn: Object.keys(unitChunkTasks),
},
'test:group:unit': {
command: `vp run --concurrency-limit ${chunkConcurrency} test:unit:chunks`,
},
...integrationFileTasks,
// The check runs after every file passed and fails when a collected file has no task.
'test:integration:files': {
command: 'node test/check-test-tasks.mjs integration',
dependsOn: Object.keys(integrationFileTasks),
},
'test:group:integration': {
command: `vp run --concurrency-limit ${maxWorkers} test:integration:files`,
cache: { untrackedEnv: e2eEnvNames },
},
// Local verification without the static checks: build the packages, then the cached test
// groups. Tests copy and build the playgrounds they use, so the playground builds of
// `build:all` are only needed by the artifact and type checks in `test:all`.
test: {
command:
"vp run --cache build && vp run --cache --filter './platform/packages/**' build && vp run test:group:platform && vp run test:group:unit && vp run test:group:integration",
cache: {
untrackedEnv: ['VOID_E2E_CF_TOKEN', 'VOID_E2E_CF_ACCOUNT_ID', 'VOID_E2E_NAMESPACE'],
},
},
'test:all': {
command:
'vp run --cache build:all && node test/check-playground-build-artifacts.mjs && vp check && vp run --cache check:types && vp run test:group:platform && vp run test:group:unit && vp run test:group:integration',
// `vp run` passes ONLY the env vars a task declares to that task — not the full environment.
// Without this, the gated live Cloudflare e2e's credentials never reach `vp test run`, so it
// skips even when the CI job injects them. `untrackedEnv` forwards them without folding them
// into the task's cache fingerprint (credentials must not bust the cache).
cache: {
untrackedEnv: ['VOID_E2E_CF_TOKEN', 'VOID_E2E_CF_ACCOUNT_ID', 'VOID_E2E_NAMESPACE'],
},
},
},
},
staged: {
'*': 'vp fmt --no-error-on-unmatched-pattern',
'*.{js,jsx,ts,tsx,mjs,cjs}': 'vp lint',
},
fmt: {
singleQuote: true,
experimentalSortImports: {
newlinesBetween: false,
},
experimentalSortPackageJson: {
sortScripts: true,
},
ignorePatterns: [
'.svelte-kit/**',
'packages/void/docs/**',
'packages/void/skills/void/docs/**',
'platform/packages/api/src/admin/fate/client.generated.ts',
'playground/**/.astro/**',
'playground/**/.nuxt/**',
'playground/**/.output/**',
'playground/**/.react-router/**',
'playground/**/.svelte-kit/**',
'playground/**/build/**',
'playground/**/src/routeTree.gen.ts',
'playground/**/wrangler.json',
'playground/**/wrangler.jsonc',
'playground/vinext-app/.next/**',
'playground/vinext-app/next-env.d.ts',
],
},
lint: {
categories: {
correctness: 'off',
},
env: {
browser: true,
builtin: true,
es2024: true,
node: true,
},
jsPlugins: [
{
name: 'vite-plus',
specifier: 'vite-plus/oxlint-plugin',
},
{
name: 'react-hooks-js',
specifier: 'eslint-plugin-react-hooks',
},
],
plugins: ['typescript', 'import', 'react', 'unicorn', 'vitest', 'node', 'jsdoc', 'oxc'],
ignorePatterns: [
'**/node_modules/**',
'**/dist/**',
'**/.void/**',
'**/.vite-cloud/**',
'**/.wrangler/**',
'**/.tanstack/**',
'**/.vitepress/cache/**',
'**/*.tsbuildinfo',
'.pnpm-store/**',
'playground-local/**',
'.worktrees/**',
],
overrides: [
{
// Fate may emit unused imports; still lint and typecheck the generated client.
files: ['platform/packages/api/src/admin/fate/client.generated.ts'],
rules: { 'no-unused-vars': 'off' },
},
{
files: ['**/*.ts', '**/*.tsx', '**/*.mts', '**/*.cts'],
rules: {
'constructor-super': 'off',
'getter-return': 'off',
'no-class-assign': 'off',
'no-const-assign': 'off',
'no-dupe-class-members': 'off',
'no-dupe-keys': 'off',
'no-func-assign': 'off',
'no-import-assign': 'off',
'no-new-native-nonconstructor': 'off',
'no-obj-calls': 'off',
'no-redeclare': 'off',
'no-setter-return': 'off',
'no-this-before-super': 'off',
'no-undef': 'off',
'no-unreachable': 'off',
'no-unsafe-negation': 'off',
'no-with': 'off',
'prefer-rest-params': 'error',
'prefer-spread': 'error',
},
},
{
files: [
'packages/react/**/*',
'playground/named-layouts/**/*',
'playground/node-app/**/*',
'playground/node-static/**/*',
'playground/pg-test/**/*',
'playground/react-pages/**/*',
'playground/react-router/**/*',
'playground/spa/**/*',
'playground/ssr/**/*',
'playground/tanstack-start/**/*',
'playground/vinext-app/**/*',
'playground/vinext-pages/**/*',
'playground/websockets/**/*',
],
rules: {
'react-hooks-js/component-hook-factories': 'error',
'react-hooks-js/config': 'error',
'react-hooks-js/error-boundaries': 'error',
'react-hooks-js/gating': 'error',
'react-hooks-js/globals': 'error',
'react-hooks-js/immutability': 'error',
'react-hooks-js/incompatible-library': 'error',
'react-hooks-js/preserve-manual-memoization': 'error',
'react-hooks-js/purity': 'error',
'react-hooks-js/refs': 'error',
'react-hooks-js/set-state-in-effect': 'error',
'react-hooks-js/set-state-in-render': 'error',
'react-hooks-js/static-components': 'error',
'react-hooks-js/unsupported-syntax': 'error',
'react-hooks-js/use-memo': 'error',
},
},
{
files: ['**/*.svelte'],
rules: {
'no-undef': 'off',
'prefer-const': 'off',
},
},
{
files: ['**/*.vue'],
rules: {
'no-undef': 'off',
},
},
{
files: ['platform/**/*'],
rules: {
// The hosted platform historically used Node's native path module.
// Keep its existing lint contract while shared SDK code uses pathslash.
'no-restricted-imports': 'off',
},
},
{
files: ['**/test/**/*.{js,jsx,ts,tsx,mjs,cjs}'],
rules: {
// Tests must derive expected paths independently of production's
// forward-slash wrapper, including on Windows.
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'pathslash',
importNames: [
'dirname',
'extname',
'isAbsolute',
'join',
'normalize',
'relative',
'resolve',
],
message:
'Use node:path for filesystem paths in tests; reserve pathslash for toSlash.',
},
],
},
],
},
},
{
files: ['playground/vinext-app/.next/**/*.ts'],
rules: {
'@typescript-eslint/array-type': 'off',
},
},
],
rules: {
'@typescript-eslint/array-type': [
'error',
{
default: 'generic',
},
],
'@typescript-eslint/no-duplicate-enum-values': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
// Enforced across the workspace by both `vp check` and `vp lint`.
'@typescript-eslint/no-floating-promises': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unsafe-declaration-merging': 'error',
'@typescript-eslint/no-wrapper-object-types': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-namespace-keyword': 'error',
'@typescript-eslint/triple-slash-reference': 'error',
curly: 'error',
'for-direction': 'error',
'getter-return': 'error',
'import/default': 'error',
'import/namespace': 'error',
'no-array-constructor': 'error',
'no-async-promise-executor': 'error',
'no-case-declarations': 'error',
'no-class-assign': 'error',
'no-compare-neg-zero': 'error',
'no-cond-assign': 'error',
'no-const-assign': 'error',
'no-constant-binary-expression': 'error',
'no-constant-condition': 'error',
'no-control-regex': 'error',
'no-debugger': 'error',
'no-delete-var': 'error',
'no-dupe-class-members': 'error',
'no-dupe-else-if': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty-character-class': 'error',
'no-empty-pattern': 'error',
'no-empty-static-block': 'error',
'no-empty': 'error',
'no-ex-assign': 'error',
'no-extra-boolean-cast': 'error',
'no-fallthrough': 'error',
'no-func-assign': 'error',
'no-global-assign': 'error',
'no-import-assign': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-loss-of-precision': 'error',
'no-misleading-character-class': 'error',
'no-new-native-nonconstructor': 'error',
'no-nonoctal-decimal-escape': 'error',
'no-obj-calls': 'error',
'no-prototype-builtins': 'error',
'no-redeclare': 'error',
'no-regex-spaces': 'error',
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'node:path',
message:
"Use `pathslash` instead. It re-exports the same API but always emits forward slashes, which avoids cross-platform breakage when paths are embedded in module specifiers, generated source, or compared against Vite's normalized watcher events. If you genuinely need format-specific behavior, import `node:path/win32` or `node:path/posix` explicitly.",
},
{
name: 'path',
message:
'Use `pathslash` instead of the unprefixed `path` import (and prefer `node:path/win32` / `node:path/posix` for explicit format-specific behavior).',
},
],
},
],
'no-self-assign': 'error',
'no-setter-return': 'error',
'no-shadow-restricted-names': 'error',
'no-sparse-arrays': 'error',
'no-this-before-super': 'error',
'no-undef': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': 'error',
'no-unused-labels': 'error',
'no-unused-private-class-members': 'error',
// Also covers packages without TypeScript's `noUnusedLocals` and plain JS scripts.
// An options object drops oxlint's default `^_` ignore pattern, so restate it.
'no-unused-vars': ['error', { args: 'none', varsIgnorePattern: '^_' }],
'no-useless-backreference': 'error',
'no-useless-catch': 'error',
'no-useless-escape': 'error',
'no-useless-rename': 'error',
'no-var': 'error',
'no-warning-comments': [
'error',
{
terms: ['@nocommit'],
},
],
'no-with': 'error',
'oxc/no-accumulating-spread': 'error',
'prefer-const': 'error',
'react/exhaustive-deps': 'error',
'react/jsx-key': 'error',
'react/jsx-no-duplicate-props': 'error',
'react/jsx-no-target-blank': 'error',
'react/jsx-no-undef': 'error',
'react/no-children-prop': 'error',
'react/no-danger-with-children': 'error',
'react/no-direct-mutation-state': 'error',
'react/no-find-dom-node': 'error',
'react/no-is-mounted': 'error',
'react/no-render-return-value': 'error',
'react/no-string-refs': 'error',
'react/require-render-return': 'error',
'require-yield': 'error',
'unicorn/consistent-empty-array-spread': 'error',
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/no-invalid-fetch-options': 'error',
'unicorn/no-typeof-undefined': 'error',
'unicorn/no-unnecessary-slice-end': 'error',
'unicorn/no-useless-promise-resolve-reject': 'error',
'unicorn/no-useless-spread': 'error',
'unicorn/prefer-array-flat-map': 'error',
'unicorn/prefer-array-index-of': 'error',
'unicorn/prefer-array-some': 'error',
'unicorn/prefer-native-coercion-functions': 'error',
'unicorn/prefer-node-protocol': 'error',
'unicorn/prefer-optional-catch-binding': 'error',
'unicorn/prefer-set-size': 'error',
'use-isnan': 'error',
'valid-typeof': 'error',
// Import test APIs from `vite-plus/test`, not `vitest`.
'vite-plus/prefer-vite-plus-imports': 'error',
// Vitest rejects `.only` only in CI; catch it locally and in pre-commit too.
'vitest/no-focused-tests': 'error',
},
options: {
typeAware: true,
typeCheck: true,
},
},
resolve: { alias: platformAlias },
test: {
fsModuleCache: true,
// Reuse Node's compiled JS/TypeScript across real subprocesses and forks.
// Vitest disables it for V8 coverage; also honor standalone Node coverage.
env: {
NODE_COMPILE_CACHE:
process.env.NODE_COMPILE_CACHE ??
fileURLToPath(new URL('./node_modules/.cache/node-compile', import.meta.url)),
...(process.env.NODE_V8_COVERAGE ? { NODE_DISABLE_COMPILE_CACHE: '1' } : {}),
},
silent: 'passed-only',
sequence: { sequencer: SuiteSequencer },
// Node 24 bundles undici 7. Its fetch() calls socket.setTypeOfService() on each new
// connection and does not catch errors. On macOS this throws EINVAL when the server has
// already reset the connection, e.g. when a test polls a port while Vite briefly binds it
// to check that it is free. The fetch still rejects and the caller sees that; only this
// stray uncaught copy is dropped. undici 8.8+ ignores the error itself.
onUnhandledError(error) {
const { code, syscall } = error as { code?: unknown; syscall?: unknown };
return !(syscall === 'setTypeOfService' && code === 'EINVAL');
},
projects: [
{
extends: false,
test: {
name: 'cli-unit',
fsModuleCache: true,
css: { include: [/starter-ui\.css(?:\?|$)/] },
include: cliUnitTests,
pool: 'threads',
maxWorkers,
// These files run their real subprocess tests concurrently. A test then also waits
// while its neighbours block the thread in a synchronous spawn, so Vitest's 5-second
// default is too short on a busy machine.
testTimeout: 20_000,
},
},
{
extends: false,
test: {
name: 'unit',
fsModuleCache: true,
css: { include: [/starter-ui\.css(?:\?|$)/] },
include: unitTestGlobs,
exclude: [...cliUnitTests, ...sdkPgliteUnitTests],
sequence: { groupOrder: 2 },
pool: 'threads',
maxWorkers,
// Windows unit tests that import the plugin or spawn a CLI can exceed Vitest's
// 5-second default under CI load. Keep the faster default on other platforms.
...(process.platform === 'win32' ? { testTimeout: 20_000 } : {}),
},
},
{
extends: false,
test: {
name: 'unit-pglite',
fsModuleCache: true,
include: sdkPgliteUnitTests,
sequence: { groupOrder: 2 },
// Native Node 24 worker crashes can abort the run on Linux and macOS.
// Keep PGlite's Wasm heap in a separate process for each database.
pool: ['linux', 'darwin'].includes(process.platform) ? 'forks' : 'threads',
maxWorkers,
...(process.platform === 'win32' ? { testTimeout: 20_000 } : {}),
},
},
{
extends: false,
resolve: { alias: platformAlias },
test: {
name: 'platform-unit',
fsModuleCache: true,
pool: 'threads',
include: platformTestGlobs,
exclude: ['platform/packages/api/test/integration/**', ...pgliteUnitTests],
maxWorkers,
},
},
{
extends: false,
resolve: { alias: platformAlias },
test: {
name: 'platform-unit-pglite',
fsModuleCache: true,
// Native Node 24 worker crashes can abort the run on Linux and macOS.
// Keep PGlite's Wasm heap in a separate process for each database.
pool: ['linux', 'darwin'].includes(process.platform) ? 'forks' : 'threads',
include: pgliteUnitTests,
maxWorkers,
},
},
{
extends: false,
resolve: { alias: platformAlias },
test: {
name: 'platform-api-integration',
fsModuleCache: true,
include: apiTimezoneTests,
globalSetup: ['platform/packages/api/test/integration/global-setup.ts'],
setupFiles: ['platform/packages/api/test/integration/setup.ts'],
...(process.env.VOID_TEST_DATABASE_URL ? { fileParallelism: false } : {}),
maxWorkers,
},
},
{
extends: false,
resolve: { alias: platformAlias },
test: {
name: 'platform-api-integration-threads',
fsModuleCache: true,
// Native Node 24 worker crashes can abort the run on Linux and macOS.
// Keep PGlite's Wasm heap in a separate process for each database.
pool: ['linux', 'darwin'].includes(process.platform) ? 'forks' : 'threads',
include: ['platform/packages/api/test/integration/**/*.test.ts'],
exclude: apiTimezoneTests,
globalSetup: ['platform/packages/api/test/integration/global-setup.ts'],
setupFiles: ['platform/packages/api/test/integration/setup.ts'],
...(process.env.VOID_TEST_DATABASE_URL ? { fileParallelism: false } : {}),
maxWorkers,
},
},
{
extends: false,
test: {
// Every integration file here owns its fixture directory, so one worker pool can
// schedule the longest files first and fill idle slots across package boundaries.
name: 'parallel-integration',
fsModuleCache: true,
pool: 'forks',
// Bound simultaneous database engines and framework compilers locally.
// Unit tests still fill unused integration workers in the same phase.
sequence: { groupOrder: 2 },
// maxWorkers limits files, not describe.concurrent tests. On Windows CI, two files
// at Vitest's default concurrency open up to ten isolated browser contexts at once.
// Reduce socket pressure while keeping file-level parallelism and other OSes unchanged.
...(process.platform === 'win32'
? { maxConcurrency: 2, setupFiles: ['test/windows-integration-setup.ts'] }
: {}),
testTimeout,
hookTimeout,
// Kept alongside the e2e glob below so a newly added e2e file gets its credentials
// forwarded past vitest's worker env filter here too (see e2eWorkerEnv). The one
// existing e2e file drives playground/spa, while the other SPA integration uses an
// isolated playground-local copy so both remain safe when credentials are present.
env: e2eWorkerEnv,
include: integrationTestDirs.map((dir) => `${dir}/**/*.test.ts`),
maxWorkers,
},
},
],
},
});
const groupedProjects = Object.values(testGroups).flat();
for (const project of config.test?.projects ?? []) {
const name = typeof project === 'object' && 'test' in project ? project.test?.name : undefined;
if (
typeof name !== 'string' ||
groupedProjects.filter((grouped) => grouped === name).length !== 1
) {
throw new Error(
`Vitest project ${JSON.stringify(name)} must be listed in exactly one entry of testGroups in vite.config.ts.`,
);
}
}
export default config;