// A checkout nested under `.claude/` must not add its tests to this suite. // The test plants one in a temporary directory next to a real test file and // asks vitest, with this repo's config, which test files it would run. import { afterEach, describe, expect, it } from "vitest"; import { execFileSync } from "node:child_process"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; const repoRoot = fileURLToPath(new URL("../../", import.meta.url)); let root = ""; afterEach(() => { rmSync(root, { recursive: true, force: true }); }); const writeTest = (path: string): void => { mkdirSync(join(root, path, ".."), { recursive: true }); writeFileSync( join(root, path), 'import { it } from "vitest";\nit("runs", () => {});\n', ); }; describe("vitest.config.ts", () => { it("does not collect tests from a checkout nested under .claude/", () => { root = mkdtempSync(join(tmpdir(), "quak-nested-checkout-")); writeTest("test/real.test.ts"); writeTest(".claude/worktrees/other/test/real.test.ts"); const output = execFileSync( process.execPath, [ join(repoRoot, "node_modules/vitest/vitest.mjs"), "list", "--filesOnly", "--config", join(repoRoot, "vitest.config.ts"), "--root", root, ], { cwd: root, encoding: "utf-8" }, ); const files = output.split("\n").filter((line) => line !== ""); expect(files).toEqual(["test/real.test.ts"]); }); });