Skip to content

Commit 73eec8c

Browse files
committed
Fix test reporting
1 parent 33b0a05 commit 73eec8c

3 files changed

Lines changed: 80 additions & 5 deletions

File tree

playwright-jasmine.js

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ let coverageArtifactId = 0;
2323
export async function expectNoJasmineFailures(page, url, options = {}) {
2424
const diagnostics = await runJasminePage(page, url, options);
2525
expect(
26-
diagnostics.failedSpecs,
26+
{
27+
overallStatus: diagnostics.overallStatus,
28+
failedSpecs: diagnostics.failedSpecs,
29+
failedSuites: diagnostics.failedSuites,
30+
globalFailures: diagnostics.globalFailures,
31+
},
2732
formatJasmineFailureReport(url, diagnostics),
28-
).toEqual([]);
33+
).toEqual({
34+
overallStatus: "passed",
35+
failedSpecs: [],
36+
failedSuites: [],
37+
globalFailures: [],
38+
});
2939
}
3040
/**
3141
* Waits for the browser-side Jasmine runner to finish and collects failures.
@@ -97,6 +107,14 @@ async function collectJasmineDiagnostics(page) {
97107
typeof reporter?.status === "function" ? reporter.status() : null;
98108
const specs =
99109
typeof reporter?.specResults === "function" ? reporter.specResults() : [];
110+
const suites =
111+
typeof reporter?.suiteResults === "function"
112+
? reporter.suiteResults()
113+
: [];
114+
const runDetails =
115+
reporter && typeof reporter.runDetails === "object"
116+
? reporter.runDetails
117+
: {};
100118
const failedSpecs = specs
101119
.filter((spec) => spec.status === "failed")
102120
.map((spec) => ({
@@ -105,9 +123,26 @@ async function collectJasmineDiagnostics(page) {
105123
(expectation) => expectation.message,
106124
),
107125
}));
126+
const failedSuites = suites
127+
.filter((suite) => suite.status === "failed")
128+
.map((suite) => ({
129+
fullName: suite.fullName,
130+
failedExpectations: (suite.failedExpectations || []).map(
131+
(expectation) => expectation.message,
132+
),
133+
}));
134+
const globalFailures = (runDetails.failedExpectations || []).map(
135+
(expectation) => expectation.message,
136+
);
108137
return {
109138
failedSpecs,
139+
failedSuites,
140+
globalFailures,
110141
overallText,
142+
overallStatus:
143+
typeof runDetails.overallStatus === "string"
144+
? runDetails.overallStatus
145+
: null,
111146
status,
112147
totalSpecs: specs.length,
113148
pageErrors: [],
@@ -128,6 +163,9 @@ function formatJasmineFailureReport(url, diagnostics) {
128163
if (diagnostics.status && diagnostics.status !== "done") {
129164
lines.push(`Status: ${diagnostics.status}`);
130165
}
166+
if (diagnostics.overallStatus) {
167+
lines.push(`Overall status: ${diagnostics.overallStatus}`);
168+
}
131169
if (diagnostics.overallText) {
132170
lines.push(`Summary: ${diagnostics.overallText}`);
133171
}
@@ -147,8 +185,38 @@ function formatJasmineFailureReport(url, diagnostics) {
147185
`... ${diagnostics.failedSpecs.length - MAX_FAILURES} more failed specs`,
148186
);
149187
}
150-
} else {
151-
lines.push("No failed specs were reported.");
188+
}
189+
if (diagnostics.failedSuites.length > 0) {
190+
lines.push("Failed suites:");
191+
diagnostics.failedSuites.slice(0, MAX_FAILURES).forEach((suite, index) => {
192+
lines.push(`${index + 1}. ${suite.fullName}`);
193+
suite.failedExpectations.slice(0, MAX_MESSAGES).forEach((message) => {
194+
lines.push(` - ${message}`);
195+
});
196+
});
197+
if (diagnostics.failedSuites.length > MAX_FAILURES) {
198+
lines.push(
199+
`... ${diagnostics.failedSuites.length - MAX_FAILURES} more failed suites`,
200+
);
201+
}
202+
}
203+
if (diagnostics.globalFailures.length > 0) {
204+
lines.push("Global failures:");
205+
diagnostics.globalFailures.slice(0, MAX_FAILURES).forEach((message) => {
206+
lines.push(`- ${message}`);
207+
});
208+
if (diagnostics.globalFailures.length > MAX_FAILURES) {
209+
lines.push(
210+
`... ${diagnostics.globalFailures.length - MAX_FAILURES} more global failures`,
211+
);
212+
}
213+
}
214+
if (
215+
diagnostics.failedSpecs.length === 0 &&
216+
diagnostics.failedSuites.length === 0 &&
217+
diagnostics.globalFailures.length === 0
218+
) {
219+
lines.push("No failed specs, suites, or global failures were reported.");
152220
}
153221
appendLogSection(lines, "Page errors", diagnostics.pageErrors);
154222
appendLogSection(lines, "Console errors", diagnostics.consoleErrors);
@@ -210,7 +278,13 @@ function sanitizeCoverageLabel(label) {
210278
* fullName: string,
211279
* failedExpectations: string[],
212280
* }>,
281+
* failedSuites: Array<{
282+
* fullName: string,
283+
* failedExpectations: string[],
284+
* }>,
285+
* globalFailures: string[],
213286
* overallText: string,
287+
* overallStatus: string | null,
214288
* status: string | null,
215289
* totalSpecs: number,
216290
* pageErrors: string[],

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ export default defineConfig({
7777
webServer: {
7878
command: "make serve",
7979
url: baseUrl,
80-
reuseExistingServer: !process.env.CI,
80+
reuseExistingServer: true,
8181
},
8282
});

utils/vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default defineConfig({
1515
: [],
1616
server: {
1717
port: 4000,
18+
strictPort: true,
1819
proxy: {
1920
"/mock": {
2021
target: "http://localhost:3000/",

0 commit comments

Comments
 (0)