Files
ECC/tests/lib/helpers/mini-test-runner.js
Alexis D.andGitHub ff15079b9f test(lib): extract shared mini test runner for coordination tests (#2663)
Address CodeRabbit review on #2311: dedupe the local test(name, fn)
harness and route all reporter output through a shared helper
(tests/lib/helpers/mini-test-runner.js) instead of direct console.log.
2026-08-04 00:29:31 -04:00

57 lines
1.1 KiB
JavaScript

/**
* Shared mini test harness for standalone tests/lib/*.test.js scripts.
*
* Centralizes test execution and console reporting so individual test
* files don't duplicate the runner or log directly.
*/
'use strict';
function report(message) {
console.log(message);
}
function test(name, fn) {
try {
fn();
report(` ✓ ${name}`);
return true;
} catch (err) {
report(` ✗ ${name}`);
report(` Error: ${err.message}`);
return false;
}
}
async function testAsync(name, fn) {
try {
await fn();
report(` ✓ ${name}`);
return true;
} catch (err) {
report(` ✗ ${name}`);
report(` Error: ${err.message}`);
return false;
}
}
function banner(title) {
report(`\n=== ${title} ===`);
}
function section(label) {
report(`\n${label}`);
}
function summary(passed, failed) {
report(`\n Results: ${passed} passed, ${failed} failed`);
if (failed > 0) process.exit(1);
}
function fatal(message) {
console.error(message);
process.exit(1);
}
module.exports = { test, testAsync, banner, section, summary, fatal };