Skip to content

Commit 011dc55

Browse files
committed
report specific test failure names
1 parent e7d17dc commit 011dc55

File tree

2 files changed

+76
-32
lines changed

2 files changed

+76
-32
lines changed

site/e2e/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const localURL = (port: number, path: string): string => {
1515
};
1616

1717
export default defineConfig({
18+
preserveOutput: "failures-only",
1819
projects: [
1920
{
2021
name: "setup",

site/e2e/reporter.ts

Lines changed: 75 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,72 +6,82 @@ import type {
66
TestResult,
77
FullResult,
88
Reporter,
9+
TestError,
910
} from "@playwright/test/reporter";
1011
import axios from "axios";
1112
import type { Writable } from "stream";
1213

13-
const testOutput = new Map<string, Array<[Writable, string]>>();
14-
1514
class CoderReporter implements Reporter {
15+
config: FullConfig | null = null;
16+
testOutput = new Map<string, Array<[Writable, string]>>();
17+
passedCount = 0;
18+
failedTests: TestCase[] = [];
19+
timedOutTests: TestCase[] = [];
20+
1621
onBegin(config: FullConfig, suite: Suite) {
22+
this.config = config;
1723
// eslint-disable-next-line no-console -- Helpful for debugging
1824
console.log(`==> Running ${suite.allTests().length} tests`);
1925
}
2026

2127
onTestBegin(test: TestCase) {
22-
testOutput.set(test.id, []);
28+
this.testOutput.set(test.id, []);
2329
// eslint-disable-next-line no-console -- Helpful for debugging
2430
console.log(`==> Starting test ${test.title}`);
2531
}
2632

2733
onStdOut(chunk: string, test?: TestCase, _?: TestResult): void {
2834
if (!test) {
29-
// console.log(`[stdout] [unknown] ${chunk.replace(/\n$/g, "")}`);
35+
const preserve = this.config?.preserveOutput === "always";
36+
if (preserve) {
37+
console.log(`[stdout] ${chunk.replace(/\n$/g, "")}`);
38+
}
3039
return;
3140
}
32-
testOutput.get(test.id)!.push([process.stdout, chunk]);
41+
this.testOutput.get(test.id)!.push([process.stdout, chunk]);
3342
}
3443

3544
onStdErr(chunk: string, test?: TestCase, _?: TestResult): void {
3645
if (!test) {
37-
// console.error(`[stderr] [unknown] ${chunk.replace(/\n$/g, "")}`);
46+
const preserve = this.config?.preserveOutput === "always";
47+
if (preserve) {
48+
console.error(`[stderr] ${chunk.replace(/\n$/g, "")}`);
49+
}
3850
return;
3951
}
40-
testOutput.get(test.id)!.push([process.stderr, chunk]);
52+
this.testOutput.get(test.id)!.push([process.stderr, chunk]);
4153
}
4254

4355
async onTestEnd(test: TestCase, result: TestResult) {
44-
// eslint-disable-next-line no-console -- Helpful for debugging
45-
console.log(`==> Finished test ${test.title}: ${result.status}`);
56+
console.log(`==> Finished test ${test.title}: ${result.status}`); // eslint-disable-line no-console -- Helpful for debugging
57+
58+
if (result.status === "passed") {
59+
this.passedCount++;
60+
}
61+
62+
if (result.status === "failed") {
63+
this.failedTests.push(test);
64+
}
4665

47-
if (result.status !== "passed") {
48-
// eslint-disable-next-line no-console -- Debugging output
49-
console.log("==> Output");
50-
const output = testOutput.get(test.id)!;
66+
if (result.status === "timedOut") {
67+
this.timedOutTests.push(test);
68+
}
69+
70+
const preserve = this.config?.preserveOutput;
71+
const logOutput =
72+
preserve === "always" ||
73+
(result.status !== "passed" && preserve !== "never");
74+
if (logOutput) {
75+
console.log("==> Output"); // eslint-disable-line no-console -- Debugging output
76+
const output = this.testOutput.get(test.id)!;
5177
for (const [target, chunk] of output) {
5278
target.write(`${chunk.replace(/\n$/g, "")}\n`);
5379
}
5480

5581
if (result.errors.length > 0) {
56-
// eslint-disable-next-line no-console -- Debugging output
57-
console.log("==> Errors");
82+
console.log("==> Errors"); // eslint-disable-line no-console -- Debugging output
5883
for (const error of result.errors) {
59-
if (error.location) {
60-
// eslint-disable-next-line no-console -- Debugging output
61-
console.log(`${error.location.file}:${error.location.line}:`);
62-
}
63-
if (error.snippet) {
64-
// eslint-disable-next-line no-console -- Debugging output
65-
console.log(error.snippet);
66-
}
67-
68-
if (error.message) {
69-
// eslint-disable-next-line no-console -- Debugging output
70-
console.log(error.message);
71-
} else {
72-
// eslint-disable-next-line no-console -- Debugging output
73-
console.log(error);
74-
}
84+
reportError(error);
7585
}
7686
}
7787

@@ -84,13 +94,27 @@ class CoderReporter implements Reporter {
8494
}
8595
}
8696
}
87-
testOutput.delete(test.id);
97+
this.testOutput.delete(test.id);
98+
8899
await exportDebugPprof(test.title);
89100
}
90101

91102
onEnd(result: FullResult) {
92103
// eslint-disable-next-line no-console -- Helpful for debugging
93104
console.log(`==> Tests ${result.status}`);
105+
console.log(`${this.passedCount} passed`);
106+
if (this.failedTests.length > 0) {
107+
console.log(`${this.failedTests.length} failed`);
108+
for (const test of this.failedTests) {
109+
console.log(` ${test.location.file}${test.title}`);
110+
}
111+
}
112+
if (this.timedOutTests.length > 0) {
113+
console.log(`${this.timedOutTests.length} timed out`);
114+
for (const test of this.timedOutTests) {
115+
console.log(` ${test.location.file}${test.title}`);
116+
}
117+
}
94118
}
95119
}
96120

@@ -119,5 +143,24 @@ const exportDebugPprof = async (testName: string) => {
119143
});
120144
};
121145

146+
const reportError = (error: TestError) => {
147+
if (error.location) {
148+
// eslint-disable-next-line no-console -- Debugging output
149+
console.log(`${error.location.file}:${error.location.line}:`);
150+
}
151+
if (error.snippet) {
152+
// eslint-disable-next-line no-console -- Debugging output
153+
console.log(error.snippet);
154+
}
155+
156+
if (error.message) {
157+
// eslint-disable-next-line no-console -- Debugging output
158+
console.log(error.message);
159+
} else {
160+
// eslint-disable-next-line no-console -- Debugging output
161+
console.log(error);
162+
}
163+
};
164+
122165
// eslint-disable-next-line no-unused-vars -- Playwright config uses it
123166
export default CoderReporter;

0 commit comments

Comments
 (0)