Skip to content

Commit

Permalink
Merge pull request #4 from estruyf/dev
Browse files Browse the repository at this point in the history
Add extra info to the summary
  • Loading branch information
estruyf authored Jan 30, 2024
2 parents 0ef1930 + a4f1be3 commit 88734a4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

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

## [1.4.0]

- Add total passed, failed, and skipped to the summary

## [1.3.0]

- Added warning test icon
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@estruyf/github-actions-reporter",
"version": "1.3.0",
"version": "1.4.0",
"description": "GitHub Actions reporter for Playwright",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -41,4 +41,4 @@
"peerDependencies": {
"@playwright/test": "^1.37.0"
}
}
}
19 changes: 18 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getTestStatusIcon } from "./utils/getTestStatusIcon";
import { SUMMARY_ENV_VAR } from "@actions/core/lib/summary";
import { join } from "path";
import { existsSync, unlinkSync, writeFileSync } from "fs";
import { getTotalStatus } from "./utils/getTotalStatus";

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

summary.addRaw(`Total tests: ${this.suite.allTests().length}`);
const totalStatus = getTotalStatus(this.suite?.suites);

const headerText = [`Total tests: ${this.suite.allTests().length}`];

if (totalStatus.passed > 0) {
headerText.push(`Passed: ${totalStatus.passed}`);
}

if (totalStatus.failed > 0) {
headerText.push(`Failed: ${totalStatus.failed}`);
}

if (totalStatus.skipped > 0) {
headerText.push(`Skipped: ${totalStatus.skipped}`);
}

summary.addRaw(headerText.join(` - `));

if (this.options.useDetails) {
summary.addSeparator();
Expand Down
34 changes: 34 additions & 0 deletions src/utils/getTotalStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Suite } from "@playwright/test/reporter";

export const getTotalStatus = (
suites: Suite[]
): {
passed: number;
failed: number;
skipped: number;
} => {
let total = {
passed: 0,
failed: 0,
skipped: 0,
};

for (const suite of suites) {
const testOutcome = suite.allTests().map((test) => {
const lastResult = test.results[test.results.length - 1];
return lastResult.status;
});

for (const outcome of testOutcome) {
if (outcome === "passed") {
total.passed++;
} else if (outcome === "failed") {
total.failed++;
} else if (outcome === "skipped") {
total.skipped++;
}
}
}

return total;
};

0 comments on commit 88734a4

Please sign in to comment.