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.
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { dropStaleWorkerDatabases, resolveTestDatabaseUri, truncateAllData } from "./test-db";
|
|
import { failureMarkerPresent } from "./vitest-marker";
|
|
|
|
/**
|
|
* Post-run cleanup returned by tests/vitest-global.ts (Vitest 4 removed the
|
|
* `globalTeardown` config option entirely; the supported contract is that
|
|
* globalSetup returns this function). Failures here must never fail the run;
|
|
* leftovers are dropped by the next run's globalSetup sweep regardless.
|
|
*
|
|
* - Workers mode: drop every `<base>_w<N>` clone after a green run; keep them
|
|
* when the failure marker exists (postmortem) or `KEEP_TEST_DBS=1`. The
|
|
* template itself survives across runs and is only rebuilt on hash mismatch
|
|
* or `TEST_DB_HARD_RESET=1`.
|
|
* - Legacy serial mode (`TEST_DATABASE_URI` set): truncate for hygiene.
|
|
*/
|
|
export default async function vitestTeardown(): Promise<void> {
|
|
try {
|
|
if (process.env.TEST_DATABASE_URI) {
|
|
await truncateAllData(resolveTestDatabaseUri());
|
|
return;
|
|
}
|
|
if (process.env.KEEP_TEST_DBS === "1" || failureMarkerPresent()) {
|
|
console.log("[test-db] keeping worker clones (failed run or KEEP_TEST_DBS=1)");
|
|
return;
|
|
}
|
|
await dropStaleWorkerDatabases();
|
|
} catch (error) {
|
|
console.warn("[test-db] teardown cleanup failed:", error);
|
|
}
|
|
}
|