forked from security/hakurei
cmd/pkgserver: fix multi-line JS test output display
This commit is contained in:
@@ -17,6 +17,9 @@ details.test-node {
|
||||
p.test-desc {
|
||||
margin: 0 0 0 1rem;
|
||||
padding: 2px 0;
|
||||
> pre {
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.italic {
|
||||
|
||||
@@ -176,16 +176,10 @@ export class StreamReporter implements Reporter {
|
||||
|
||||
for (const [path, tests] of pathMap) {
|
||||
if (tests.length === 1) {
|
||||
const t = tests[0];
|
||||
const pathStr = path ? `${path} ❯ ` : "";
|
||||
const output = t.output ? `: ${t.output}` : "";
|
||||
this.stream.writeln(`${pathStr}${t.name}${output}`);
|
||||
this.#writeOutput(tests[0], path ? `${path} ❯ ` : "", false);
|
||||
} else {
|
||||
this.stream.writeln(path);
|
||||
for (const t of tests) {
|
||||
const output = t.output ? `: ${t.output}` : "";
|
||||
this.stream.writeln(` - ${t.name}${output}`);
|
||||
}
|
||||
for (const t of tests) this.#writeOutput(t, " - ", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,6 +187,20 @@ export class StreamReporter implements Reporter {
|
||||
const { successes, failures } = this.counts;
|
||||
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 {
|
||||
@@ -228,9 +236,9 @@ export class DOMReporter implements Reporter {
|
||||
const p = document.createElement("p");
|
||||
p.classList.add("test-desc");
|
||||
if (result.output) {
|
||||
const code = document.createElement("code");
|
||||
code.appendChild(document.createTextNode(result.output));
|
||||
p.appendChild(code);
|
||||
const pre = document.createElement("pre");
|
||||
pre.appendChild(document.createTextNode(result.output));
|
||||
p.appendChild(pre);
|
||||
} else {
|
||||
p.classList.add("italic");
|
||||
p.appendChild(document.createTextNode("No output."));
|
||||
|
||||
Reference in New Issue
Block a user