Skip to content

Commit 410f31b

Browse files
committed
refactor: update report script to group tests by file
1 parent 3147832 commit 410f31b

File tree

5 files changed

+102
-115
lines changed

5 files changed

+102
-115
lines changed

.github/workflows/playwright-crit-flow-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
if: always()
5050
id: generate_comment
5151
run: |
52-
node test/e2e_tests/scripts/create-playwright-report-summary.js
52+
node --experimental-strip-types test/e2e_tests/scripts/create-playwright-report-summary.ts
5353
COMMENT=$(cat playwright-report-summary.txt)
5454
echo "comment<<EOF" >> $GITHUB_OUTPUT
5555
echo "$COMMENT" >> $GITHUB_OUTPUT

.github/workflows/precommit-crit-flows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ jobs:
174174
if: always()
175175
id: generate_comment
176176
run: |
177-
node test/e2e_tests/scripts/create-playwright-report-summary.js
177+
node --experimental-strip-types test/e2e_tests/scripts/create-playwright-report-summary.ts
178178
COMMENT=$(cat playwright-report-summary.txt)
179179
echo "comment<<EOF" >> $GITHUB_OUTPUT
180180
echo "$COMMENT" >> $GITHUB_OUTPUT

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.16
1+
22.18

test/e2e_tests/scripts/create-playwright-report-summary.js

Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*
18+
*/
19+
20+
import type {JSONReport, JSONReportSuite, JSONReportTest} from '@playwright/test/reporter';
21+
22+
import {readFileSync, writeFileSync} from 'fs';
23+
import {resolve} from 'path';
24+
25+
const jsonPath = resolve('playwright-report', 'report.json');
26+
let report: JSONReport;
27+
28+
try {
29+
report = JSON.parse(readFileSync(jsonPath, 'utf-8'));
30+
} catch (error) {
31+
const errorMessage = `❌ Error: report.json not found at ${jsonPath} ❌`;
32+
writeFileSync('playwright-report-summary.txt', errorMessage);
33+
process.exit(1);
34+
}
35+
36+
const getTests = (suite: JSONReportSuite): (JSONReportTest & {file: string; title: string; tags: string[]})[] => {
37+
return [
38+
...(suite.specs.flatMap(spec =>
39+
spec.tests.map(test => ({
40+
...test,
41+
file: spec.file,
42+
// If no title is provided the file would be used which is redundant
43+
title: spec.file !== suite.title ? `${suite.title} > ${spec.title}` : spec.title,
44+
tags: spec.tags,
45+
})),
46+
) ?? []),
47+
...(suite.suites?.flatMap(suite => getTests(suite)) ?? []),
48+
];
49+
};
50+
51+
const tests = report.suites.flatMap(suite => getTests(suite));
52+
const failedOrFlakyTests = tests.filter(test => test.status === 'unexpected' || test.status === 'flaky');
53+
const testFilesToReport = Object.groupBy(failedOrFlakyTests, test => test.file);
54+
55+
const testDetails = Object.values(testFilesToReport).reduce((acc, testFile) => {
56+
if (!testFile?.length) {
57+
return acc;
58+
}
59+
60+
const failedTests = testFile
61+
.filter(test => test.status === 'unexpected')
62+
.map(({title, tags}) => `❌ ${title} (tags: ${tags.join(', ')})`);
63+
64+
const flakyTests = testFile
65+
.filter(test => test.status === 'flaky')
66+
.map(({title, tags}) => `⚠️ ${title} (tags: ${tags.join(', ')})`);
67+
68+
acc += `
69+
<details>
70+
<summary>${testFile[0].file} (❌ ${failedTests.length} failed, ⚠️ ${flakyTests.length} flaky)</summary>
71+
72+
${[...failedTests, ...flakyTests].join('\n ')}
73+
</details>
74+
`;
75+
76+
return acc;
77+
}, '');
78+
79+
const formatDuration = (duration: number) => {
80+
const minutes = Math.floor(duration / 60000);
81+
const totalSeconds = Math.round((duration % 60000) / 1000);
82+
const seconds = totalSeconds % 60;
83+
return `~ ${minutes} min ${seconds} sec`;
84+
};
85+
86+
const summary = `
87+
### 🧪 Playwright Test Summary
88+
89+
- ✅ **Passed:** ${report.stats.expected}
90+
- ❌ **Failed:** ${report.stats.unexpected}
91+
- ⏭ **Skipped:** ${report.stats.skipped}
92+
- 🔁 **Flaky:** ${report.stats.flaky}
93+
- 📊 **Total:** ${report.stats.expected + report.stats.unexpected + report.stats.skipped + report.stats.flaky}
94+
- ⏱ **Total Runtime:** ${(report.stats.duration / 1000).toFixed(1)}s (${formatDuration(report.stats.duration)})
95+
96+
${testDetails}
97+
`;
98+
99+
writeFileSync('playwright-report-summary.txt', summary);

0 commit comments

Comments
 (0)