Files
scriptc/tests/harness/node-test-normalize.ts
2026-07-22 18:08:04 -05:00

31 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* The node:test differential's documented output normalization —
* node-test.test.ts's function, extracted so the Linux lane applies the
* IDENTICAL scrub to both of its in-container lanes. Node's spec reporter
* embeds real durations in every line (raw byte-compare is impossible for
* ANY node:test program); stack frames and the inspect property block a
* frame opens are runner-internal output the compiled runtime
* deliberately omits (SEMANTICS.md). Everything else must match
* byte-exactly. */
/** The documented normalization — durations, frames, the property block. */
export function normalizeNodeTestOutput(stdout: string): string {
const out: string[] = [];
let inPropBlock = false;
for (const line of stdout.split("\n")) {
if (inPropBlock) {
if (/^\s*\}\s*$/.test(line)) inPropBlock = false;
continue;
}
if (/^\s+at /.test(line)) {
if (line.trimEnd().endsWith("{")) inPropBlock = true;
continue;
}
out.push(
line
.replace(/\(\d+(?:\.\d+)?ms\)/g, "(Xms)")
.replace(/^ℹ duration_ms .*$/, "ℹ duration_ms X"),
);
}
return out.join("\n");
}