1
0
forked from security/hakurei

cmd/pkgserver: fix multi-line JS test output display

This commit is contained in:
Kat
2026-03-15 00:50:37 +11:00
parent 2a3f6f5384
commit 6f78444b11
2 changed files with 22 additions and 11 deletions

View File

@@ -17,6 +17,9 @@ details.test-node {
p.test-desc { p.test-desc {
margin: 0 0 0 1rem; margin: 0 0 0 1rem;
padding: 2px 0; padding: 2px 0;
> pre {
margin: 0;
}
} }
.italic { .italic {

View File

@@ -176,16 +176,10 @@ export class StreamReporter implements Reporter {
for (const [path, tests] of pathMap) { for (const [path, tests] of pathMap) {
if (tests.length === 1) { if (tests.length === 1) {
const t = tests[0]; this.#writeOutput(tests[0], path ? `${path} ` : "", false);
const pathStr = path ? `${path} ` : "";
const output = t.output ? `: ${t.output}` : "";
this.stream.writeln(`${pathStr}${t.name}${output}`);
} else { } else {
this.stream.writeln(path); this.stream.writeln(path);
for (const t of tests) { for (const t of tests) this.#writeOutput(t, " - ", true);
const output = t.output ? `: ${t.output}` : "";
this.stream.writeln(` - ${t.name}${output}`);
}
} }
} }
@@ -193,6 +187,20 @@ export class StreamReporter implements Reporter {
const { successes, failures } = this.counts; const { successes, failures } = this.counts;
this.stream.writeln(`${successes} succeeded, ${failures} failed`); this.stream.writeln(`${successes} succeeded, ${failures} failed`);
} }
#writeOutput(test: { name: string } & TestResult, prefix: string, nested: boolean) {
let output = "";
if (test.output) {
const lines = test.output.split("\n");
if (lines.length <= 1) {
output = `: ${test.output}`;
} else {
const padding = nested ? " " : " ";
output = ":\n" + lines.map((line) => padding + line).join("\n");
}
}
this.stream.writeln(`${prefix}${test.name}${output}`);
}
} }
export class DOMReporter implements Reporter { export class DOMReporter implements Reporter {
@@ -228,9 +236,9 @@ export class DOMReporter implements Reporter {
const p = document.createElement("p"); const p = document.createElement("p");
p.classList.add("test-desc"); p.classList.add("test-desc");
if (result.output) { if (result.output) {
const code = document.createElement("code"); const pre = document.createElement("pre");
code.appendChild(document.createTextNode(result.output)); pre.appendChild(document.createTextNode(result.output));
p.appendChild(code); p.appendChild(pre);
} else { } else {
p.classList.add("italic"); p.classList.add("italic");
p.appendChild(document.createTextNode("No output.")); p.appendChild(document.createTextNode("No output."));