Skip to content

Commit 3cb0e7a

Browse files
TMHSDigitalclaude
andcommitted
tests: report earlier failures when a test crashes, and count checks for real
A test that throws, as opposed to one that fails an assertion, used to end the run before the failure list printed, hiding every earlier failure. Both test files now print the failures so far, the last assertion that ran, and the error. checks.test counts the V-rules its assertions cover instead of printing a hard-coded "30 checks". Part of #203. The node:test migration is still open. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LpkeXRUqm7oDedPDk3QWtK
1 parent 0f679a2 commit 3cb0e7a

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

‎site/checks.test.mjs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,26 @@ const spdxAllowed = new Set(
5656
let passed = 0;
5757
const failures = [];
5858

59+
// A test that throws (rather than failing an assertion) ends the run. Report
60+
// what had already failed and where the run stopped, so one crash does not
61+
// hide the failures before it.
62+
let lastLabel = "(none yet)";
63+
process.on("uncaughtException", (err) => {
64+
console.error(`checks.test crashed after ${passed} passing assertions; the last one was "${lastLabel}".`);
65+
for (const f of failures) console.error(` - ${f}`);
66+
console.error(err && err.stack ? err.stack : err);
67+
process.exit(1);
68+
});
69+
/** The V-rule names the assertions cover, so the summary counts them instead of restating a number. */
70+
const checksSeen = new Set();
71+
const note = (label) => {
72+
lastLabel = label;
73+
const v = String(label).match(/^V\d+/);
74+
if (v) checksSeen.add(v[0]);
75+
};
76+
5977
function rejects(label, errors, needle) {
78+
note(label);
6079
if (!errors.length) {
6180
failures.push(`${label}: expected an error, got none`);
6281
return;
@@ -71,11 +90,13 @@ function rejects(label, errors, needle) {
7190
}
7291

7392
function eq(label, actual, expected) {
93+
note(label);
7494
if (actual === expected) passed += 1;
7595
else failures.push(`${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
7696
}
7797

7898
function accepts(label, errors) {
99+
note(label);
79100
if (errors.length) {
80101
failures.push(`${label}: expected no error, got: ${errors.join(" | ")}`);
81102
return;
@@ -873,4 +894,4 @@ if (failures.length) {
873894
for (const f of failures) console.error(` - ${f}`);
874895
process.exit(1);
875896
}
876-
console.log(`checks.test ok: ${passed} assertions across 30 checks`);
897+
console.log(`checks.test ok: ${passed} assertions across ${checksSeen.size} checks`);

‎site/lib/lib.test.mjs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,34 @@ import { atomFeed, catalogCsv } from "./exports.mjs";
1616
let passed = 0;
1717
const failures = [];
1818

19+
// A test that throws (rather than failing an assertion) ends the run. Report
20+
// what had already failed and where the run stopped, so one crash does not
21+
// hide the failures before it.
22+
let lastLabel = "(none yet)";
23+
process.on("uncaughtException", (err) => {
24+
console.error(`lib.test crashed after ${passed} passing assertions; the last one was "${lastLabel}".`);
25+
for (const f of failures) console.error(` - ${f}`);
26+
console.error(err && err.stack ? err.stack : err);
27+
process.exit(1);
28+
});
29+
1930
function eq(label, actual, expected) {
31+
lastLabel = label;
2032
if (actual === expected) passed += 1;
2133
else failures.push(`${label}: expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
2234
}
2335
function has(label, text, needle) {
36+
lastLabel = label;
2437
if (String(text).includes(needle)) passed += 1;
2538
else failures.push(`${label}: expected to contain ${JSON.stringify(needle)}`);
2639
}
2740
function lacks(label, text, needle) {
41+
lastLabel = label;
2842
if (!String(text).includes(needle)) passed += 1;
2943
else failures.push(`${label}: expected not to contain ${JSON.stringify(needle)}`);
3044
}
3145
function throws(label, fn, needle) {
46+
lastLabel = label;
3247
try {
3348
fn();
3449
failures.push(`${label}: expected an error`);

0 commit comments

Comments
 (0)