1
0
forked from security/hakurei

cmd/pkgserver: move StreamReporter display() to Reporter interface

This commit is contained in:
Kat
2026-03-14 14:23:10 +11:00
parent 0b3be27b9a
commit ef8663461b

View File

@@ -8,6 +8,7 @@ export interface TestResult {
export interface Reporter { export interface Reporter {
update(path: string[], result: TestResult): void; update(path: string[], result: TestResult): void;
finalize(): void;
} }
export interface Stream { export interface Stream {
@@ -40,7 +41,7 @@ export class StreamReporter implements Reporter {
} }
} }
display() { finalize() {
// Transform [{ path: ["a", "b", "c"] }, { path: ["a", "b", "d"] }] // Transform [{ path: ["a", "b", "c"] }, { path: ["a", "b", "d"] }]
// into { "a b": ["c", "d"] }. // into { "a b": ["c", "d"] }.
let pathMap = new Map<string, ({ name: string } & TestResult)[]>(); let pathMap = new Map<string, ({ name: string } & TestResult)[]>();
@@ -117,6 +118,8 @@ export class DOMReporter implements Reporter {
} }
parent.appendChild(p); parent.appendChild(p);
} }
finalize() {}
} }
let r = typeof document !== "undefined" ? new DOMReporter() : new StreamReporter({ writeln: console.log }); let r = typeof document !== "undefined" ? new DOMReporter() : new StreamReporter({ writeln: console.log });
@@ -127,4 +130,4 @@ r.update(["Tetromino", "generate", "tessellates"], { success: false, output: "as
r.update(["Tetromino", "solve", "works"], { success: true, output: "" }); r.update(["Tetromino", "solve", "works"], { success: true, output: "" });
r.update(["discombobulate"], { success: false, output: "hippopotamonstrosesquippedaliophobia" }); r.update(["discombobulate"], { success: false, output: "hippopotamonstrosesquippedaliophobia" });
r.update(["recombobulate"], { success: true, output: "" }); r.update(["recombobulate"], { success: true, output: "" });
if (r instanceof StreamReporter) r.display(); r.finalize();