// // Tiny assertion helpers shared by the suites. Each suite owns a Checker; the // process exit code comes from its failure count. // class Checker { constructor() { this.failures = 0; } /** Records a pass or failure. `detail` is printed only when it fails. */ check(label, condition, detail) { if (condition) { console.log(` ok ${label}`); return true; } this.failures += 1; console.log(` FAIL ${label}${detail !== undefined ? " — " + detail : ""}`); return false; } /** Deep-ish equality by JSON shape, which is enough for these fixtures. */ equals(label, actual, expected) { return this.check( label, JSON.stringify(actual) === JSON.stringify(expected), `got ${JSON.stringify(actual)}, want ${JSON.stringify(expected)}`, ); } section(title) { console.log(`\n=== ${title} ===`); } /** Prints the tally and exits non-zero when anything failed. */ finish(name) { if (this.failures === 0) { console.log(`\nALL ${name} PASSED`); process.exit(0); } console.log(`\n${this.failures} ${name} FAILED`); process.exit(1); } } module.exports = { Checker };