Skip to content

Commit e9f21c0

Browse files
committed
test(coverage): raise coverage gate margin
Cover release and coverage guardrail edge cases so the CI threshold has more stable headroom without weakening enforcement.
1 parent 44ea55d commit e9f21c0

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

src/coverage-threshold.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,37 @@ All files | 91.05 | 92.03 |
1717

1818
expect(parseAllFilesLineCoverage(output)).toBe(92.03);
1919
});
20+
21+
test("returns undefined when Bun output has no all-files coverage row", () => {
22+
const output = "160 pass\n0 fail\nRan 160 tests across 11 files.";
23+
24+
expect(parseAllFilesLineCoverage(output)).toBeUndefined();
25+
});
2026
});
2127

2228
describe("assertCoverageThreshold", () => {
29+
test("accepts line coverage at the minimum and reports the passing value", () => {
30+
const messages: string[] = [];
31+
const originalLog = console.log;
32+
console.log = (message?: unknown) => {
33+
messages.push(String(message));
34+
};
35+
36+
try {
37+
assertCoverageThreshold("All files | 91.05 | 80.00 |", 80);
38+
} finally {
39+
console.log = originalLog;
40+
}
41+
42+
expect(messages).toEqual(["Coverage OK: 80.00%"]);
43+
});
44+
45+
test("throws when no coverage summary is present", () => {
46+
expect(() => assertCoverageThreshold("160 pass\n0 fail", 80)).toThrow(
47+
"No coverage summary found.",
48+
);
49+
});
50+
2351
test("throws when line coverage is below the minimum", () => {
2452
const output = "All files | 91.05 | 79.99 |";
2553

src/release-sanity.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ describe("checkReleaseSanity", () => {
1919
).toEqual([]);
2020
});
2121

22+
test("rejects invalid package versions before checking release files", () => {
23+
expect(
24+
checkReleaseSanity({
25+
packageJson: { ...BASE_PACKAGE, version: "1.2" },
26+
changelog: "",
27+
githubRef: "refs/tags/v1.2.3",
28+
distFiles: ["coverage-threshold.js"],
29+
}),
30+
).toEqual(["package.json version must be a valid semver string."]);
31+
});
32+
2233
test("reports mismatched tags and missing changelog entries", () => {
2334
expect(
2435
checkReleaseSanity({
@@ -50,4 +61,18 @@ describe("checkReleaseSanity", () => {
5061
}),
5162
).toEqual(["dist must not include test-only artifact server/test-harness.js."]);
5263
});
64+
65+
test("rejects generated dist artifacts for test and release helper files", () => {
66+
expect(
67+
checkReleaseSanity({
68+
packageJson: BASE_PACKAGE,
69+
changelog: "## [1.2.3] — 2026-04-26\n",
70+
distFiles: ["server.js", "server.test.js", "coverage-threshold.js", "release-sanity.js"],
71+
}),
72+
).toEqual([
73+
"dist must not include test-only artifact server.test.js.",
74+
"dist must not include test-only artifact coverage-threshold.js.",
75+
"dist must not include test-only artifact release-sanity.js.",
76+
]);
77+
});
5378
});

0 commit comments

Comments
 (0)