forked from rosa/hakurei
cmd/pkgserver: serialize raw log list for go test consumption
This commit is contained in:
@@ -35,11 +35,11 @@ function checkDuplicates(parent: string, names: { name: string }[]) {
|
|||||||
class FailNowSentinel {}
|
class FailNowSentinel {}
|
||||||
|
|
||||||
export class TestController {
|
export class TestController {
|
||||||
#logBuf: string[];
|
#logs: string[];
|
||||||
#failed: boolean;
|
#failed: boolean;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#logBuf = [];
|
this.#logs = [];
|
||||||
this.#failed = false;
|
this.#failed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ export class TestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log(message: string) {
|
log(message: string) {
|
||||||
this.#logBuf.push(message);
|
this.#logs.push(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
error(message: string) {
|
error(message: string) {
|
||||||
@@ -70,8 +70,8 @@ export class TestController {
|
|||||||
this.failNow();
|
this.failNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
getLog(): string {
|
getLog(): string[] {
|
||||||
return this.#logBuf.join("\n");
|
return this.#logs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ export class TestController {
|
|||||||
|
|
||||||
export interface TestResult {
|
export interface TestResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
output: string;
|
logs: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function run(reporter: Reporter) {
|
export function run(reporter: Reporter) {
|
||||||
@@ -105,7 +105,7 @@ function runTests(reporter: Reporter, parents: string[], node: TestTree) {
|
|||||||
controller.error(extractExceptionString(e));
|
controller.error(extractExceptionString(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reporter.update(path, { success: !controller.failed(), output: controller.getLog() });
|
reporter.update(path, { success: !controller.failed(), logs: controller.getLog() });
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractExceptionString(e: any): string {
|
function extractExceptionString(e: any): string {
|
||||||
@@ -192,10 +192,13 @@ export class StreamReporter implements Reporter {
|
|||||||
|
|
||||||
#writeOutput(test: { name: string } & TestResult, prefix: string, nested: boolean) {
|
#writeOutput(test: { name: string } & TestResult, prefix: string, nested: boolean) {
|
||||||
let output = "";
|
let output = "";
|
||||||
if (test.output) {
|
if (test.logs.length) {
|
||||||
const lines = test.output.split("\n");
|
// Individual logs might span multiple lines, so join them together
|
||||||
|
// then split it again.
|
||||||
|
const logStr = test.logs.join("\n");
|
||||||
|
const lines = logStr.split("\n");
|
||||||
if (lines.length <= 1) {
|
if (lines.length <= 1) {
|
||||||
output = `: ${test.output}`;
|
output = `: ${logStr}`;
|
||||||
} else {
|
} else {
|
||||||
const padding = nested ? " " : " ";
|
const padding = nested ? " " : " ";
|
||||||
output = ":\n" + lines.map((line) => padding + line).join("\n");
|
output = ":\n" + lines.map((line) => padding + line).join("\n");
|
||||||
@@ -239,9 +242,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.logs.length) {
|
||||||
const pre = document.createElement("pre");
|
const pre = document.createElement("pre");
|
||||||
pre.appendChild(document.createTextNode(result.output));
|
pre.appendChild(document.createTextNode(result.logs.join("\n")));
|
||||||
p.appendChild(pre);
|
p.appendChild(pre);
|
||||||
} else {
|
} else {
|
||||||
p.classList.add("italic");
|
p.classList.add("italic");
|
||||||
|
|||||||
Reference in New Issue
Block a user