Stage 3 of the int-suite speedup (gate G2 showed Vitest 4's pool scheduler only reuses worker processes between isolate:false tasks, so per-file fork spawning made clone+boot costs unavoidable at stage 2): - config: workers branch runs pool=forks with isolate:false, cap 8 via VITEST_MAX_FORKS, node default env (jsdom docblocks on DOM specs), failure-marker reporter, and idempotent setupFiles chain - vitest-worker-setup: one template clone PER FORK PROCESS named by pid (VITEST_WORKER_ID churns per task, which silently re-cloned per file); DATABASE_URI repoint + TEST_PG_POOL_MAX=8 (measured hook deadlocks at 3) - vitest.setup: once-per-process serial test URI markers; afterEach useRealTimers guard (restoreAllMocks omitted: it resurrects vi.mock module factories mid-file); logging absorber for fire-and-forget event writes that reject after their spec's cleanup deleted fixture users - helpers/get-test-payload.ts: memoized Payload boot shared across files in a fork; codemod converted all 91 self-booting specs mechanically - pinned opt-outs (own boot + comments): game-structures-labor-route, mission-reminder, notification-inbox-scope (jwtSign writes leak into the shared instance's auth state across files) - promotion-nominations: create the superuser before its rank ladder so the Users-hook Recruit rank gets leading orderable tokens (its top-of-ladder guard needs Col to remain ladder-max on fresh clones); operation-economy: itemType-scope the market-state assertion (asset and resource ids collide as bare integers under per-fork databases) Gate G3: 5 consecutive full green runs (149/149 files), warm wall 53-65s vs 598s baseline (~10x), zero clone residue after green runs. Vitest 4 note: globalTeardown config no longer exists; teardown returns from globalSetup.
42 lines
1.9 KiB
TypeScript
42 lines
1.9 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.
|
|
//
|
|
// isolate:false is load-bearing, not just an optimization: the
|
|
// Vitest 4 pool scheduler REUSES fork processes only between
|
|
// non-isolated tasks (cli-api schedule()), and module/instance
|
|
// persistence across files is what lets tests/helpers/
|
|
// get-test-payload.ts memoize the Payload boot. Per-file
|
|
// state-leak risk is blunted by the afterEach cleanup harness in
|
|
// vitest.setup.ts; specs that still misbehave opt out by booting
|
|
// their own payload instance (see helper docstring).
|
|
fileParallelism: true,
|
|
pool: "forks" as const,
|
|
isolate: false,
|
|
maxWorkers: maxForks,
|
|
}),
|
|
},
|
|
});
|