Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test(ci): keep module mocks in isolated test projects
A module mock registered after another file in the same worker loaded the
module never applies, so a mocking test in a project that shares one module
graph passes or fails with file scheduling. That is how the environment
export source tests failed on hosted runs until c324d31 removed their
mocks.

Guard the rule: every tracked test using vi.mock or vi.doMock must belong
to an isolated project. Move the last shared-graph case,
DirectAnalysisStatFailure, which mocks node:fs/promises, into process-global
beside the other module-mocking workflow tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
kaoru0822-kitauji and claude committed Oct 21, 2026
commit 3f8c78c78497ead35f225f712a79eaf8c5aa8168
41 changes: 41 additions & 0 deletions tests/boundary/filesystem/ciTestProjects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,44 @@ describe("canonical test-project ownership", () => {
},
);
});

describe("test module isolation", () => {
it("keeps module mocks out of projects that share one module graph", async () => {
// A mock registered after another file in the same worker loaded the
// module never applies, so the test's outcome depends on file scheduling.
const root = await createTestTempDirectory("rea-vitest-mock-isolation-");
const script = join(root, "project-isolation.mjs");
await writeFile(
script,
`
import config from ${JSON.stringify(pathToFileURL(join(repository, "vitest.config.ts")).href)};
console.log(JSON.stringify(Object.fromEntries(
config.test.projects.map(project => [project.test.name, project.test.isolate !== false]),
)));
`,
);
const result = await execFileOutput(
process.execPath,
["--import", "tsx", script],
{
cwd: repository,
timeout: 10_000,
maxBuffer: 64 * 1024,
stopSignal: "SIGTERM",
},
);
const isolated = JSON.parse(result.stdout) as Record<string, boolean>;
const mocking = execFileSync(
"git",
["grep", "-l", "-E", String.raw`vi\.(mock|doMock)\(`, "--", "*.test.ts"],
{ cwd: repository, encoding: "utf8" },
)
.trim()
.split("\n")
.filter(Boolean);
expect(mocking.length).toBeGreaterThan(0);
expect(
mocking.filter((file) => isolated[projectForTest(file).name] !== true),
).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ vi.mock("node:fs/promises", async (importOriginal) => {
};
});

import { parseConfig } from "../config/parseConfig.js";
import { classifyBinaryTargetFilesystemFailure } from "./BinaryTargetResolver.js";
import type { BinarySession } from "./binary/BinarySession.js";
import type { DirectAnalysisDependencies } from "./DirectAnalysisDependencies.js";
import { runProviderAnalysis } from "./DirectAnalysis.js";
import { parseConfig } from "../../src/config/parseConfig.js";
import { classifyBinaryTargetFilesystemFailure } from "../../src/application/BinaryTargetResolver.js";
import type { BinarySession } from "../../src/application/binary/BinarySession.js";
import type { DirectAnalysisDependencies } from "../../src/application/DirectAnalysisDependencies.js";
import { runProviderAnalysis } from "../../src/application/DirectAnalysis.js";

afterEach(() => statFailures.clear());

Expand Down
Loading