Skip to content

Commit 05ba3bd

Browse files
committed
Added show error option
1 parent d4c3f8d commit 05ba3bd

File tree

6 files changed

+66
-41
lines changed

6 files changed

+66
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
- Added OS name
99
- Added browser/project name
1010
- Added retries count
11+
- Added `showError` option
1112

1213
## [1.0.0]
1314

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The reporter supports the following configuration options:
3535
| --- | --- | --- |
3636
| title | Title of the report | `Test results` |
3737
| useDetails | Use details in summary which creates expandable content | `false` |
38+
| showError | Show error message in summary | `false` |
3839

3940
To use these option, you can update the reporter configuration:
4041

@@ -45,7 +46,8 @@ export default defineConfig({
4546
reporter: [
4647
['@estruyf/github-actions-reporter', {
4748
title: 'My custom title',
48-
useDetails: true
49+
useDetails: true,
50+
showError: true
4951
}]
5052
],
5153
});

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const config: PlaywrightTestConfig<{}, {}> = {
1111
retries: process.env.CI ? 2 : 1,
1212
workers: process.env.CI ? 1 : undefined,
1313
reporter: [
14-
["./src/index.ts", { title: "Reporter testing" }],
14+
["./src/index.ts", { title: "Reporter testing", showError: true }],
1515
[
1616
"./src/index.ts",
1717
{ title: "Reporter testing with details", useDetails: true },

src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Convert from "ansi-to-html";
1515
interface GitHubActionOptions {
1616
title?: string;
1717
useDetails?: boolean;
18+
showError?: boolean;
1819
}
1920

2021
class GitHubAction implements Reporter {
@@ -68,7 +69,10 @@ class GitHubAction implements Reporter {
6869
const fileName = basename(filePath);
6970

7071
if (this.options.useDetails) {
71-
const content = getHtmlTable(tests[filePath]);
72+
const content = getHtmlTable(
73+
tests[filePath],
74+
!!this.options.showError
75+
);
7276

7377
// Check if there are any failed tests
7478
const hasFailedTests = checkForFailedTests(tests[filePath]);
@@ -87,7 +91,10 @@ class GitHubAction implements Reporter {
8791
2
8892
);
8993

90-
const tableRows = getTableRows(tests[filePath]);
94+
const tableRows = getTableRows(
95+
tests[filePath],
96+
!!this.options.showError
97+
);
9198
summary.addTable(tableRows);
9299
}
93100
}

src/utils/getHtmlTable.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { TestCase } from "@playwright/test/reporter";
22
import Convert from "ansi-to-html";
33

4-
export const getHtmlTable = (tests: TestCase[]): string => {
4+
export const getHtmlTable = (tests: TestCase[], showError: boolean): string => {
55
const convert = new Convert();
66

77
const content: string[] = [];
@@ -14,7 +14,9 @@ export const getHtmlTable = (tests: TestCase[]): string => {
1414
content.push(`<th>Status</th>`);
1515
content.push(`<th>Duration</th>`);
1616
content.push(`<th>Retries</th>`);
17-
content.push(`<th>Error</th>`);
17+
if (showError) {
18+
content.push(`<th>Error</th>`);
19+
}
1820
content.push(`</tr>`);
1921
content.push(`</thead>`);
2022
content.push(`<tbody>`);
@@ -30,13 +32,15 @@ export const getHtmlTable = (tests: TestCase[]): string => {
3032
);
3133
content.push(`<td>${result.duration / 1000}s</td>`);
3234
content.push(`<td>${result.retry}</td>`);
33-
content.push(
34-
`<td>${
35-
result.error && result.error.message
36-
? convert.toHtml(result.error.message!)
37-
: ""
38-
}</td>`
39-
);
35+
if (showError) {
36+
content.push(
37+
`<td>${
38+
result.error && result.error.message
39+
? convert.toHtml(result.error.message!)
40+
: ""
41+
}</td>`
42+
);
43+
}
4044
content.push(`</tr>`);
4145
}
4246

src/utils/getTableRows.ts

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,45 @@ import { SummaryTableRow } from "@actions/core/lib/summary";
22
import { TestCase } from "@playwright/test/reporter";
33
import Convert from "ansi-to-html";
44

5-
export const getTableRows = (tests: TestCase[]): SummaryTableRow[] => {
5+
export const getTableRows = (
6+
tests: TestCase[],
7+
showError: boolean
8+
): SummaryTableRow[] => {
69
const convert = new Convert();
710

8-
const tableRows = [
9-
[
10-
{
11-
data: "Test",
12-
header: true,
13-
},
14-
{
15-
data: "Status",
16-
header: true,
17-
},
18-
{
19-
data: "Duration",
20-
header: true,
21-
},
22-
{
23-
data: "Retries",
24-
header: true,
25-
},
26-
{
27-
data: "Error",
28-
header: true,
29-
},
30-
],
11+
const tableHeaders = [
12+
{
13+
data: "Test",
14+
header: true,
15+
},
16+
{
17+
data: "Status",
18+
header: true,
19+
},
20+
{
21+
data: "Duration",
22+
header: true,
23+
},
24+
{
25+
data: "Retries",
26+
header: true,
27+
},
3128
];
3229

30+
if (showError) {
31+
tableHeaders.push({
32+
data: "Error",
33+
header: true,
34+
});
35+
}
36+
37+
const tableRows = [tableHeaders];
38+
3339
for (const test of tests) {
3440
// Get the last result
3541
const result = test.results[test.results.length - 1];
3642

37-
tableRows.push([
43+
const tableRow = [
3844
{
3945
data: test.title,
4046
header: false,
@@ -51,14 +57,19 @@ export const getTableRows = (tests: TestCase[]): SummaryTableRow[] => {
5157
data: `${result.retry}`,
5258
header: false,
5359
},
54-
{
60+
];
61+
62+
if (showError) {
63+
tableRow.push({
5564
data:
5665
result.error && result.error.message
5766
? convert.toHtml(result.error.message!)
5867
: "",
5968
header: false,
60-
},
61-
]);
69+
});
70+
}
71+
72+
tableRows.push(tableRow);
6273
}
6374

6475
return tableRows;

0 commit comments

Comments
 (0)