|
| 1 | +// The test-wiring checker must catch a workspace `test:ci` never reaches (#10049). |
| 2 | +// |
| 3 | +// The failure it guards is specific: a workspace declares its own `test` script and nothing in the root |
| 4 | +// `test:ci` chain ever invokes it, so the suite sits there -- written, reviewed, never executed -- while |
| 5 | +// everything ELSE (build, pack, lint, typecheck) stays green. #10049 found exactly this for |
| 6 | +// @loopover/ui-kit's 12-file vitest suite. So the positive case here is "a declared test nobody runs is |
| 7 | +// reported", and the negative cases pin every legitimate way a workspace can be covered, since a checker |
| 8 | +// that reports a covered workspace would be noise and would get muted. |
| 9 | +import { describe, expect, it } from "vitest"; |
| 10 | + |
| 11 | +import { findTestWiringGaps } from "../../scripts/check-test-coverage-wiring"; |
| 12 | + |
| 13 | +describe("findTestWiringGaps (#10049)", () => { |
| 14 | + it("REGRESSION: reports the exact #10049 shape — ui-kit's test script the root chain never invokes", () => { |
| 15 | + const scripts = { |
| 16 | + "test:ci": "npm run ui:lint && npm run ui:typecheck && npm run ui:test", |
| 17 | + "ui:lint": "npm run ui:kit:build && npm --workspace @loopover/ui-kit run format:check", |
| 18 | + "ui:typecheck": "npm run ui:kit:build && npm --workspace @loopover/ui-kit run typecheck", |
| 19 | + // Present in the repo, but only ever builds ui-kit -- never runs its test script. |
| 20 | + "ui:test": "npm run ui:kit:build && npm --workspace @loopover/ui run test && npm --workspace @loopover/ui-miner run test", |
| 21 | + "ui:kit:build": "npm run build --workspace @loopover/ui-kit", |
| 22 | + }; |
| 23 | + expect( |
| 24 | + findTestWiringGaps(scripts, [ |
| 25 | + { name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }, |
| 26 | + { name: "@loopover/ui", dir: "apps/loopover-ui" }, |
| 27 | + ]), |
| 28 | + ).toEqual([{ workspace: "@loopover/ui-kit", script: "test" }]); |
| 29 | + }); |
| 30 | + |
| 31 | + it("counts a workspace reached THROUGH an intermediate script as covered", () => { |
| 32 | + // The fix chains ui-kit's test into ui:test; the workspace is then covered transitively. |
| 33 | + const scripts = { |
| 34 | + "test:ci": "npm run ui:test", |
| 35 | + "ui:test": "npm run ui:kit:build && npm --workspace @loopover/ui-kit run test && npm --workspace @loopover/ui run test", |
| 36 | + "ui:kit:build": "npm run build --workspace @loopover/ui-kit", |
| 37 | + }; |
| 38 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([]); |
| 39 | + }); |
| 40 | + |
| 41 | + it("reports a workspace whose BUILD is invoked but whose test is not", () => { |
| 42 | + // A build may exercise some code as a side effect, but that is not a guarantee the test script runs. |
| 43 | + const scripts = { "test:ci": "npm run ui:kit:build", "ui:kit:build": "npm run build --workspace @loopover/ui-kit" }; |
| 44 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 45 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 46 | + ]); |
| 47 | + }); |
| 48 | + |
| 49 | + it("handles the reversed flag order, since both spellings appear in this package.json", () => { |
| 50 | + const scripts = { "test:ci": "npm run test --workspace @loopover/engine" }; |
| 51 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/engine", dir: "packages/loopover-engine" }])).toEqual([]); |
| 52 | + }); |
| 53 | + |
| 54 | + it("does NOT count a non-test script invoked via --workspace as coverage", () => { |
| 55 | + const scripts = { "test:ci": "npm --workspace @loopover/ui-kit run build" }; |
| 56 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 57 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 58 | + ]); |
| 59 | + }); |
| 60 | + |
| 61 | + it("does NOT count a non-test script invoked via the reversed --workspace flag order", () => { |
| 62 | + const scripts = { "test:ci": "npm run build --workspace @loopover/ui-kit" }; |
| 63 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 64 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 65 | + ]); |
| 66 | + }); |
| 67 | + |
| 68 | + it("treats a workspace as covered when covered holds the unscoped name (scoped-name strip hit)", () => { |
| 69 | + const scripts = { "test:ci": "npm run test --workspace ui-kit" }; |
| 70 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([]); |
| 71 | + }); |
| 72 | + |
| 73 | + it("does not treat a workspace as covered via scoped-name strip when the unscoped token is absent", () => { |
| 74 | + const scripts = { "test:ci": "echo noop" }; |
| 75 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 76 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 77 | + ]); |
| 78 | + }); |
| 79 | + |
| 80 | + it("terminates on a cyclic script graph instead of looping forever", () => { |
| 81 | + const scripts = { "test:ci": "npm run a", a: "npm run b", b: "npm run a" }; |
| 82 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 83 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 84 | + ]); |
| 85 | + }); |
| 86 | + |
| 87 | + it("reports nothing when no workspace declares a test at all", () => { |
| 88 | + expect(findTestWiringGaps({ "test:ci": "echo noop" }, [])).toEqual([]); |
| 89 | + }); |
| 90 | + |
| 91 | + it("tolerates a missing entry script rather than throwing", () => { |
| 92 | + // A renamed root script must fail loudly as a REPORT, not as a crash mid-CI. |
| 93 | + expect(findTestWiringGaps({}, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([ |
| 94 | + { workspace: "@loopover/ui-kit", script: "test" }, |
| 95 | + ]); |
| 96 | + }); |
| 97 | + |
| 98 | + it("treats a workspace as covered when covered holds its directory path (npm --workspace <path> form)", () => { |
| 99 | + const scripts = { "test:ci": "npm --workspace packages/loopover-ui-kit run test" }; |
| 100 | + expect(findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }])).toEqual([]); |
| 101 | + }); |
| 102 | + |
| 103 | + it("accepts an explicit entry point other than the test:ci default", () => { |
| 104 | + const scripts = { "ui:test": "npm --workspace @loopover/ui-kit run test" }; |
| 105 | + expect( |
| 106 | + findTestWiringGaps(scripts, [{ name: "@loopover/ui-kit", dir: "packages/loopover-ui-kit" }], "ui:test"), |
| 107 | + ).toEqual([]); |
| 108 | + }); |
| 109 | +}); |
0 commit comments