| 1 | import assert from "node:assert/strict"; |
| 2 | import { readFileSync, readdirSync } from "node:fs"; |
| 3 | import test from "node:test"; |
| 4 | import { testPlan } from "./ci-test-plan.mjs"; |
| 5 | |
| 6 | const frontend = new URL("../", import.meta.url); |
| 7 | const scripts = JSON.parse(readFileSync(new URL("package.json", frontend), "utf8")).scripts; |
| 8 | const files = readdirSync(new URL("src/__tests__/", frontend)).filter(file => /\.test\.tsx?$/.test(file)); |
| 9 | |
| 10 | test("every discovered and dedicated test is scheduled exactly once", () => { |
| 11 | const plan = testPlan(scripts, files); |
| 12 | for (const file of files) { |
| 13 | assert.equal(plan.filter(entry => entry.args.includes(`src/__tests__/${file}`)).length, 1, file); |
| 14 | } |
| 15 | assert.equal(plan.filter(entry => entry.args.includes("src/components/TaskMonitorPanel.test.tsx")).length, 1); |
| 16 | assert.equal(plan.filter(entry => entry.args.includes("scripts/test-todo-visibility.mjs")).length, 1); |
| 17 | assert.ok(plan.some(entry => entry.args.includes("--self-test"))); |
| 18 | assert.ok(plan.some(entry => entry.args.includes("tsconfig.test.json"))); |
| 19 | assert.ok(plan.some(entry => entry.args.includes("bench/app-memory-shards.test.mjs"))); |
| 20 | }); |
| 21 | |
| 22 | test("asset loaders and the isolated performance benchmark retain their invocation", () => { |
| 23 | const plan = testPlan(scripts, files); |
| 24 | for (const [file, loader] of [["remote-connect-wizard", "css"], ["remote-server-panel", "svg"]]) { |
| 25 | const entry = plan.find(entry => entry.key === `src/__tests__/${file}.test.tsx`); |
| 26 | assert.ok(entry.args.includes(`./scripts/${loader}-stub-register.mjs`)); |
| 27 | } |
| 28 | assert.deepEqual(plan.filter(entry => entry.serial).map(entry => entry.key), ["src/__tests__/history-performance-benchmark.tsx"]); |
| 29 | }); |
| 30 | |
| 31 | test("future tests are discovered without registration and unknown script grammars fail closed", () => { |
| 32 | assert.ok(testPlan(scripts, [...files, "new-behavior.test.tsx"]).some(entry => entry.key.endsWith("new-behavior.test.tsx"))); |
| 33 | for (const body of ["pnpm test:motion", "echo passed", "node check.mjs || true", "node check.mjs; true"]) { |
| 34 | assert.throws(() => testPlan({ ...scripts, "test:motion": body }, files)); |
| 35 | } |
| 36 | assert.throws(() => testPlan({ ...scripts, "test:workspace": undefined }, files)); |
| 37 | }); |
| 38 | |
| 39 | test("deduplication cannot silently discard different explicit loaders", () => { |
| 40 | assert.throws(() => testPlan({ ...scripts, |
| 41 | "test:mcp-app": "node --import ./scripts/svg-stub-register.mjs --import tsx src/__tests__/terminal-events.test.ts", |
| 42 | }, files), /conflicting test invocation/); |
| 43 | }); |
| 44 |