Skip to content

Commit 88734a4

Browse files
authored
Merge pull request #4 from estruyf/dev
Add extra info to the summary
2 parents 0ef1930 + a4f1be3 commit 88734a4

File tree

5 files changed

+60
-5
lines changed

5 files changed

+60
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [1.4.0]
6+
7+
- Add total passed, failed, and skipped to the summary
8+
59
## [1.3.0]
610

711
- Added warning test icon

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@estruyf/github-actions-reporter",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "GitHub Actions reporter for Playwright",
55
"main": "dist/index.js",
66
"scripts": {
@@ -41,4 +41,4 @@
4141
"peerDependencies": {
4242
"@playwright/test": "^1.37.0"
4343
}
44-
}
44+
}

src/index.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getTestStatusIcon } from "./utils/getTestStatusIcon";
1414
import { SUMMARY_ENV_VAR } from "@actions/core/lib/summary";
1515
import { join } from "path";
1616
import { existsSync, unlinkSync, writeFileSync } from "fs";
17+
import { getTotalStatus } from "./utils/getTotalStatus";
1718

1819
interface GitHubActionOptions {
1920
title?: string;
@@ -56,7 +57,23 @@ class GitHubAction implements Reporter {
5657
const summary = core.summary;
5758
summary.addHeading(this.options.title || `Test results`, 1);
5859

59-
summary.addRaw(`Total tests: ${this.suite.allTests().length}`);
60+
const totalStatus = getTotalStatus(this.suite?.suites);
61+
62+
const headerText = [`Total tests: ${this.suite.allTests().length}`];
63+
64+
if (totalStatus.passed > 0) {
65+
headerText.push(`Passed: ${totalStatus.passed}`);
66+
}
67+
68+
if (totalStatus.failed > 0) {
69+
headerText.push(`Failed: ${totalStatus.failed}`);
70+
}
71+
72+
if (totalStatus.skipped > 0) {
73+
headerText.push(`Skipped: ${totalStatus.skipped}`);
74+
}
75+
76+
summary.addRaw(headerText.join(` - `));
6077

6178
if (this.options.useDetails) {
6279
summary.addSeparator();

src/utils/getTotalStatus.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Suite } from "@playwright/test/reporter";
2+
3+
export const getTotalStatus = (
4+
suites: Suite[]
5+
): {
6+
passed: number;
7+
failed: number;
8+
skipped: number;
9+
} => {
10+
let total = {
11+
passed: 0,
12+
failed: 0,
13+
skipped: 0,
14+
};
15+
16+
for (const suite of suites) {
17+
const testOutcome = suite.allTests().map((test) => {
18+
const lastResult = test.results[test.results.length - 1];
19+
return lastResult.status;
20+
});
21+
22+
for (const outcome of testOutcome) {
23+
if (outcome === "passed") {
24+
total.passed++;
25+
} else if (outcome === "failed") {
26+
total.failed++;
27+
} else if (outcome === "skipped") {
28+
total.skipped++;
29+
}
30+
}
31+
}
32+
33+
return total;
34+
};

0 commit comments

Comments
 (0)