1
0
Fork 0
polaris-task-force/vitest.config.mts
Z8MB1E cc8a911502 test(vitest): parallel forks with per-worker database clones
Stage 2 of the int-suite speedup: pool=forks with fileParallelism and a
default cap of 8 (VITEST_MAX_FORKS), each fork cloning the template into
ptf_*_test_w<ID> via tests/vitest-worker-setup.ts; environment defaults
to node with jsdom opt-in docblocks on the six DOM-consuming specs; a
tiny reporter writes a failure marker so post-run cleanup keeps clones
after red runs (KEEP_TEST_DBS=1 forces keeping); pg pools cap at
TEST_PG_POOL_MAX=3 per boot in workers mode. Legacy serial mode stays
reachable by setting TEST_DATABASE_URI.

Notes from the gate G2 runs (Vitest 4.0.16): globalTeardown config was
removed in Vitest 4 entirely - cleanup now returns from globalSetup. The
pool scheduler only reuses worker processes when isolate:false, so this
per-file-fork stage lands short of the wall-time target and is expected
to be superseded by the gated isolate:false stage. Gate G2 warm serial
equivalent stays green via TEST_DATABASE_URI bisect mode.
2026-10-21 10:41:57 -04:00

32 lines
1.3 KiB
TypeScript

import { defineConfig } from "vitest/config";
import react from "@vitejs/plugin-react";
import tsconfigPaths from "vite-tsconfig-paths";
// Setting TEST_DATABASE_URI forces the legacy single-database serial mode
// (bisect hatch): shared db, truncate per run, no forks and no clones.
const serialMode = Boolean(process.env.TEST_DATABASE_URI);
const maxForks = Number(process.env.VITEST_MAX_FORKS ?? 8);
export default defineConfig({
plugins: [tsconfigPaths(), react()],
test: {
// Node by default; component specs opt into jsdom with a
// `// @vitest-environment jsdom` docblock.
environment: "node",
setupFiles: ["./vitest.setup.ts", "./tests/vitest-worker-setup.ts"],
include: ["tests/int/**/*.int.spec.ts"],
globalSetup: ["./tests/vitest-global.ts"],
reporters: ["default", "./tests/vitest-reporter.ts"],
...(serialMode
? { fileParallelism: false }
: {
// Per-fork worker databases (tests/vitest-worker-setup.ts) replace
// the old serial execution: cross-file data interference is gone by
// construction because two forks never share tables. Fork cap stays
// conservative: Postgres max_connections=100 on this box plus IO.
fileParallelism: true,
pool: "forks" as const,
maxWorkers: maxForks,
}),
},
});