diff --git a/packages/cli/scripts/test-file-home.mjs b/packages/cli/scripts/test-file-home.mjs new file mode 100644 index 0000000000..acd059c18f --- /dev/null +++ b/packages/cli/scripts/test-file-home.mjs @@ -0,0 +1,10 @@ +// Each test file gets a home of its own: per-user state such as the render lock is never +// shared by test files running at the same time, so one file's render cannot make another's wait. +import { mkdtempSync, rmSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterAll } from "vitest"; + +const home = mkdtempSync(join(tmpdir(), "hf-test-file-home-")); +process.env.HOME = process.env.USERPROFILE = home; +afterAll(() => rmSync(home, { recursive: true, force: true })); diff --git a/packages/cli/src/utils/testFileHome.test.ts b/packages/cli/src/utils/testFileHome.test.ts new file mode 100644 index 0000000000..367a98481d --- /dev/null +++ b/packages/cli/src/utils/testFileHome.test.ts @@ -0,0 +1,8 @@ +import { homedir } from "node:os"; +import { hyperframesCacheDir } from "@hyperframes/core/cache-dir"; +import { expect, it } from "vitest"; + +it("gives each test file its own home, so files never share the per-user render lock", () => { + expect(homedir()).toMatch(/hf-test-file-home-/); + expect(hyperframesCacheDir("locks", "render.lock").startsWith(homedir())).toBe(true); +}); diff --git a/packages/cli/vitest.config.ts b/packages/cli/vitest.config.ts index 02bf010cd2..5c0d8bbe50 100644 --- a/packages/cli/vitest.config.ts +++ b/packages/cli/vitest.config.ts @@ -61,6 +61,7 @@ export default defineConfig({ // hang. Prefer this one config knob over per-test/per-hook timeout bandaids. testTimeout: 20_000, hookTimeout: 30_000, + setupFiles: ["./scripts/test-file-home.mjs"], // Tests that drive a real Chrome (the four *.process.test.ts named here start one) run alone, after // everything else: a Chrome beside hundreds of parallel files was starved past its 30 s launch limit. projects: [ diff --git a/scripts/test-reachability.json b/scripts/test-reachability.json index 2228af2353..8b1a8b59cc 100644 --- a/scripts/test-reachability.json +++ b/scripts/test-reachability.json @@ -62,7 +62,7 @@ "command": "vitest run --shard=${{ matrix.shard }}/2", "tests": ["packages/cli/src/**/*.test.ts"], "sources": { - "packages/cli/vitest.config.ts": "9bd2a87aaf33d3cd7fc397c30ae914468a3731a6fae1ffe7cdd1bf3450cbe900", + "packages/cli/vitest.config.ts": "135ef1c442b32ec5316b23e24d2f8cf0111d889fcb141c95dbd933cf2eaaf8f4", ".github/workflows/ci.yml#job#test-cli": "66a1249d0d3f0e6f72adb4c22bf7f76b7a8dabcee3204b6bf8cbcc636a9d7cb4", "packages/cli/package.json#script#test": "ad6cd6b8acf39571390d7bc1772410249266fa406be150a22f0065827e400496" },