forked from rosa/hakurei
cmd/pkgserver: add JSON reporter to facilitate go test integration
This commit is contained in:
3
cmd/pkgserver/ui/static/go_test_entrypoint.ts
Normal file
3
cmd/pkgserver/ui/static/go_test_entrypoint.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import "./all_tests.js";
|
||||||
|
import { GoTestReporter, run } from "./test.js";
|
||||||
|
run(new GoTestReporter());
|
||||||
@@ -84,6 +84,7 @@ export interface TestResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function run(reporter: Reporter) {
|
export function run(reporter: Reporter) {
|
||||||
|
reporter.register(TESTS);
|
||||||
for (const suite of TESTS) {
|
for (const suite of TESTS) {
|
||||||
for (const c of suite.children) runTests(reporter, [suite.name], c);
|
for (const c of suite.children) runTests(reporter, [suite.name], c);
|
||||||
}
|
}
|
||||||
@@ -122,6 +123,7 @@ function extractExceptionString(e: any): string {
|
|||||||
// Reporting
|
// Reporting
|
||||||
|
|
||||||
export interface Reporter {
|
export interface Reporter {
|
||||||
|
register(suites: TestGroup[]): void
|
||||||
update(path: string[], result: TestResult): void;
|
update(path: string[], result: TestResult): void;
|
||||||
finalize(): void;
|
finalize(): void;
|
||||||
}
|
}
|
||||||
@@ -145,6 +147,8 @@ export class StreamReporter implements Reporter {
|
|||||||
this.counts = { successes: 0, failures: 0 };
|
this.counts = { successes: 0, failures: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
register(suites: TestGroup[]) {}
|
||||||
|
|
||||||
update(path: string[], result: TestResult) {
|
update(path: string[], result: TestResult) {
|
||||||
if (path.length === 0) throw new RangeError("path is empty");
|
if (path.length === 0) throw new RangeError("path is empty");
|
||||||
const pathStr = path.join(SEP);
|
const pathStr = path.join(SEP);
|
||||||
@@ -209,6 +213,8 @@ function assertGetElementById(id: string): HTMLElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class DOMReporter implements Reporter {
|
export class DOMReporter implements Reporter {
|
||||||
|
register(suites: TestGroup[]) {}
|
||||||
|
|
||||||
update(path: string[], result: TestResult) {
|
update(path: string[], result: TestResult) {
|
||||||
if (path.length === 0) throw new RangeError("path is empty");
|
if (path.length === 0) throw new RangeError("path is empty");
|
||||||
const counter = assertGetElementById(result.success ? "successes" : "failures");
|
const counter = assertGetElementById(result.success ? "successes" : "failures");
|
||||||
@@ -255,3 +261,31 @@ export class DOMReporter implements Reporter {
|
|||||||
|
|
||||||
finalize() {}
|
finalize() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GoNode {
|
||||||
|
name: string;
|
||||||
|
subtests: GoNode[] | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Used to display results via `go test`, via some glue code from the Go side.
|
||||||
|
export class GoTestReporter implements Reporter {
|
||||||
|
// Convert a test tree into the one expected by the Go code.
|
||||||
|
static serialize(node: TestTree): GoNode {
|
||||||
|
return {
|
||||||
|
name: node.name,
|
||||||
|
subtests: "children" in node ? node.children.map(GoTestReporter.serialize) : null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
register(suites: TestGroup[]) {
|
||||||
|
console.log(JSON.stringify(suites.map(GoTestReporter.serialize)));
|
||||||
|
}
|
||||||
|
|
||||||
|
update(path: string[], result: TestResult) {
|
||||||
|
console.log(JSON.stringify({ path: path, ...result }));
|
||||||
|
}
|
||||||
|
|
||||||
|
finalize() {
|
||||||
|
console.log("null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user