Skip to content

Commit 730c19a

Browse files
committed
Merge branch 'better-playwright-reporter' into emotional-damage-6
2 parents a23213a + 335593a commit 730c19a

File tree

31 files changed

+760
-868
lines changed

31 files changed

+760
-868
lines changed

site/.eslintrc.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ rules:
9191
- allowSingleExtends: true
9292
"brace-style": "off"
9393
"curly": ["error", "all"]
94+
"eslint-comments/disable-enable-pair":
95+
- error
96+
- allowWholeFile: true
9497
"eslint-comments/require-description": "error"
9598
eqeqeq: error
9699
import/default: "off"

site/e2e/playwright.config.ts

+1
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

+100-29
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,116 @@
1-
import fs from "fs";
1+
/* eslint-disable no-console -- Logging is sort of the whole point here */
2+
import * as fs from "fs";
23
import type {
34
FullConfig,
45
Suite,
56
TestCase,
67
TestResult,
78
FullResult,
89
Reporter,
10+
TestError,
911
} from "@playwright/test/reporter";
1012
import axios from "axios";
13+
import type { Writable } from "stream";
1114

1215
class CoderReporter implements Reporter {
16+
config: FullConfig | null = null;
17+
testOutput = new Map<string, Array<[Writable, string]>>();
18+
passedCount = 0;
19+
failedTests: TestCase[] = [];
20+
timedOutTests: TestCase[] = [];
21+
1322
onBegin(config: FullConfig, suite: Suite) {
14-
// eslint-disable-next-line no-console -- Helpful for debugging
15-
console.log(`Starting the run with ${suite.allTests().length} tests`);
23+
this.config = config;
24+
console.log(`==> Running ${suite.allTests().length} tests`);
1625
}
1726

1827
onTestBegin(test: TestCase) {
19-
// eslint-disable-next-line no-console -- Helpful for debugging
20-
console.log(`Starting test ${test.title}`);
28+
this.testOutput.set(test.id, []);
29+
console.log(`==> Starting test ${test.title}`);
2130
}
2231

23-
onStdOut(chunk: string, test: TestCase, _: TestResult): void {
24-
// eslint-disable-next-line no-console -- Helpful for debugging
25-
console.log(
26-
`[stdout] [${test ? test.title : "unknown"}]: ${chunk.replace(
27-
/\n$/g,
28-
"",
29-
)}`,
30-
);
32+
onStdOut(chunk: string, test?: TestCase, _?: TestResult): void {
33+
if (!test) {
34+
const preserve = this.config?.preserveOutput === "always";
35+
if (preserve) {
36+
console.log(`[stdout] ${chunk.replace(/\n$/g, "")}`);
37+
}
38+
return;
39+
}
40+
this.testOutput.get(test.id)!.push([process.stdout, chunk]);
3141
}
3242

33-
onStdErr(chunk: string, test: TestCase, _: TestResult): void {
34-
// eslint-disable-next-line no-console -- Helpful for debugging
35-
console.log(
36-
`[stderr] [${test ? test.title : "unknown"}]: ${chunk.replace(
37-
/\n$/g,
38-
"",
39-
)}`,
40-
);
43+
onStdErr(chunk: string, test?: TestCase, _?: TestResult): void {
44+
if (!test) {
45+
const preserve = this.config?.preserveOutput === "always";
46+
if (preserve) {
47+
console.error(`[stderr] ${chunk.replace(/\n$/g, "")}`);
48+
}
49+
return;
50+
}
51+
this.testOutput.get(test.id)!.push([process.stderr, chunk]);
4152
}
4253

4354
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}`);
55+
console.log(`==> Finished test ${test.title}: ${result.status}`);
56+
57+
if (result.status === "passed") {
58+
this.passedCount++;
59+
}
4660

47-
if (result.status !== "passed") {
48-
// eslint-disable-next-line no-console -- Helpful for debugging
49-
console.log("errors", result.errors, "attachments", result.attachments);
61+
if (result.status === "failed") {
62+
this.failedTests.push(test);
5063
}
64+
65+
if (result.status === "timedOut") {
66+
this.timedOutTests.push(test);
67+
}
68+
69+
const preserve = this.config?.preserveOutput;
70+
const logOutput =
71+
preserve === "always" ||
72+
(result.status !== "passed" && preserve !== "never");
73+
if (logOutput) {
74+
console.log("==> Output");
75+
const output = this.testOutput.get(test.id)!;
76+
for (const [target, chunk] of output) {
77+
target.write(`${chunk.replace(/\n$/g, "")}\n`);
78+
}
79+
80+
if (result.errors.length > 0) {
81+
console.log("==> Errors");
82+
for (const error of result.errors) {
83+
reportError(error);
84+
}
85+
}
86+
87+
if (result.attachments.length > 0) {
88+
console.log("==> Attachments");
89+
for (const attachment of result.attachments) {
90+
console.log(attachment);
91+
}
92+
}
93+
}
94+
this.testOutput.delete(test.id);
95+
5196
await exportDebugPprof(test.title);
5297
}
5398

5499
onEnd(result: FullResult) {
55-
// eslint-disable-next-line no-console -- Helpful for debugging
56-
console.log(`Finished the run: ${result.status}`);
100+
console.log(`==> Tests ${result.status}`);
101+
console.log(`${this.passedCount} passed`);
102+
if (this.failedTests.length > 0) {
103+
console.log(`${this.failedTests.length} failed`);
104+
for (const test of this.failedTests) {
105+
console.log(` ${test.location.file}${test.title}`);
106+
}
107+
}
108+
if (this.timedOutTests.length > 0) {
109+
console.log(`${this.timedOutTests.length} timed out`);
110+
for (const test of this.timedOutTests) {
111+
console.log(` ${test.location.file}${test.title}`);
112+
}
113+
}
57114
}
58115
}
59116

@@ -72,7 +129,6 @@ const exportDebugPprof = async (testName: string) => {
72129
if (err) {
73130
throw new Error(`Error writing to ${outputFile}: ${err.message}`);
74131
} else {
75-
// eslint-disable-next-line no-console -- Helpful for debugging
76132
console.log(`Data from ${url} has been saved to ${outputFile}`);
77133
}
78134
});
@@ -82,5 +138,20 @@ const exportDebugPprof = async (testName: string) => {
82138
});
83139
};
84140

141+
const reportError = (error: TestError) => {
142+
if (error.location) {
143+
console.log(`${error.location.file}:${error.location.line}:`);
144+
}
145+
if (error.snippet) {
146+
console.log(error.snippet);
147+
}
148+
149+
if (error.message) {
150+
console.log(error.message);
151+
} else {
152+
console.log(error);
153+
}
154+
};
155+
85156
// eslint-disable-next-line no-unused-vars -- Playwright config uses it
86157
export default CoderReporter;

site/src/components/Dashboard/Navbar/UserDropdown/BorderedMenu.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { css } from "@emotion/css";
22
import { useTheme } from "@emotion/react";
3-
import Popover, { PopoverProps } from "@mui/material/Popover";
3+
import Popover, { type PopoverProps } from "@mui/material/Popover";
44
import type { FC, PropsWithChildren } from "react";
55

66
type BorderedMenuVariant = "user-dropdown";
@@ -18,7 +18,7 @@ export const BorderedMenu: FC<PropsWithChildren<BorderedMenuProps>> = ({
1818

1919
const paper = css`
2020
width: 260px;
21-
border-radius: ${theme.shape.borderRadius};
21+
border-radius: ${theme.shape.borderRadius}px;
2222
box-shadow: ${theme.shadows[6]};
2323
`;
2424

site/src/components/DeploySettingsLayout/Sidebar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const SidebarNavItem: FC<
4747
font-size: 14px;
4848
text-decoration: none;
4949
padding: ${theme.spacing(1.5, 1.5, 1.5, 2)};
50-
border-radius: ${theme.shape.borderRadius / 2};
50+
border-radius: ${theme.shape.borderRadius / 2}px;
5151
transition: background-color 0.15s ease-in-out;
5252
margin-bottom: 1;
5353
position: relative;

0 commit comments

Comments
 (0)