Skip to content

Commit ed0fcc0

Browse files
authored
Merge pull request #3 from estruyf/dev
2 parents 84383e3 + 24facc7 commit ed0fcc0

13 files changed

+104
-24
lines changed

.github/workflows/testing.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
run: npm ci
2424

2525
- name: Install Playwright Browsers
26-
run: npx playwright install --with-deps
26+
run: npx playwright install --with-deps chromium
2727

2828
- name: Run Playwright tests
2929
run: npx playwright test

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
dist
33
node_modules
44
test-results
5+
summary.html

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

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

5+
## [1.3.0]
6+
7+
- Added warning test icon
8+
- Added `skipped` status
9+
510
## [1.2.0]
611

712
- Show console logging

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "@estruyf/github-actions-reporter",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"description": "GitHub Actions reporter for Playwright",
55
"main": "dist/index.js",
66
"scripts": {
77
"build": "tsc",
88
"watch": "tsc -w",
9-
"test": "npx playwright test"
9+
"test": "NODE_ENV=development npx playwright test",
10+
"test:local": "act -j testing -P ubuntu-latest=catthehacker/ubuntu:act-latest --container-architecture linux/amd64 --env GITHUB_STEP_SUMMARY='/dev/stdout'"
1011
},
1112
"author": "Elio Struyf <[email protected]>",
1213
"license": "MIT",

playwright.config.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const config: PlaywrightTestConfig<{}, {}> = {
88
},
99
fullyParallel: false,
1010
forbidOnly: !!process.env.CI,
11-
retries: process.env.CI ? 2 : 1,
12-
workers: process.env.CI ? 1 : undefined,
11+
retries: process.env.CI ? 2 : 2,
12+
workers: process.env.CI ? 1 : 1,
1313
reporter: [
1414
["./src/index.ts", { title: "Reporter testing", showError: true }],
1515
[

src/index.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import * as core from "@actions/core";
1010
import { basename } from "path";
1111
import { getHtmlTable } from "./utils/getHtmlTable";
1212
import { getTableRows } from "./utils/getTableRows";
13-
import { checkForFailedTests } from "./utils/checkForFailedTests";
14-
import Convert from "ansi-to-html";
13+
import { getTestStatusIcon } from "./utils/getTestStatusIcon";
14+
import { SUMMARY_ENV_VAR } from "@actions/core/lib/summary";
15+
import { join } from "path";
16+
import { existsSync, unlinkSync, writeFileSync } from "fs";
1517

1618
interface GitHubActionOptions {
1719
title?: string;
@@ -39,6 +41,16 @@ class GitHubAction implements Reporter {
3941
}
4042

4143
async onEnd(result: FullResult) {
44+
if (process.env.NODE_ENV === "development") {
45+
const summaryFile = join(__dirname, "../summary.html");
46+
if (existsSync(summaryFile)) {
47+
unlinkSync(summaryFile);
48+
}
49+
writeFileSync(summaryFile, "", "utf-8");
50+
process.env[SUMMARY_ENV_VAR] = summaryFile;
51+
process.env.GITHUB_ACTIONS = "true";
52+
}
53+
4254
if (process.env.GITHUB_ACTIONS && this.suite) {
4355
const os = process.platform;
4456
const summary = core.summary;
@@ -84,10 +96,10 @@ class GitHubAction implements Reporter {
8496
);
8597

8698
// Check if there are any failed tests
87-
const hasFailedTests = checkForFailedTests(tests[filePath]);
99+
const testStatusIcon = getTestStatusIcon(tests[filePath]);
88100

89101
summary.addDetails(
90-
`${hasFailedTests ? "❌" : "✅"} ${fileName} (${os}${
102+
`${testStatusIcon} ${fileName} (${os}${
91103
project!.name ? ` / ${project!.name}` : ""
92104
})`,
93105
content

src/utils/checkForFailedTests.ts

-9
This file was deleted.

src/utils/getHtmlTable.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { TestCase } from "@playwright/test/reporter";
22
import Convert from "ansi-to-html";
3+
import { getTestStatus } from "./getTestStatus";
34

45
export const getHtmlTable = (tests: TestCase[], showError: boolean): string => {
56
const convert = new Convert();
@@ -27,9 +28,7 @@ export const getHtmlTable = (tests: TestCase[], showError: boolean): string => {
2728

2829
content.push(`<tr>`);
2930
content.push(`<td>${test.title}</td>`);
30-
content.push(
31-
`<td>${result.status === "passed" ? "✅ Pass" : "❌ Fail"}</td>`
32-
);
31+
content.push(`<td>${getTestStatus(result)}</td>`);
3332
content.push(`<td>${result.duration / 1000}s</td>`);
3433
content.push(`<td>${result.retry}</td>`);
3534
if (showError) {

src/utils/getTableRows.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SummaryTableRow } from "@actions/core/lib/summary";
22
import { TestCase } from "@playwright/test/reporter";
33
import Convert from "ansi-to-html";
4+
import { getTestStatus } from "./getTestStatus";
45

56
export const getTableRows = (
67
tests: TestCase[],
@@ -46,7 +47,7 @@ export const getTableRows = (
4647
header: false,
4748
},
4849
{
49-
data: result.status === "passed" ? "✅ Pass" : "❌ Fail",
50+
data: getTestStatus(result),
5051
header: false,
5152
},
5253
{

src/utils/getTestStatus.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TestResult } from "@playwright/test/reporter";
2+
3+
export const getTestStatus = (result: TestResult) => {
4+
let value = "";
5+
6+
if (result.status === "passed" && result.retry > 0) {
7+
value = `⚠️ Pass`;
8+
} else if (result.status === "passed") {
9+
value = "✅ Pass";
10+
} else if (result.status === "skipped") {
11+
value = `⚠️ Skipped`;
12+
} else {
13+
value = "❌ Fail";
14+
}
15+
16+
return value;
17+
};

src/utils/getTestStatusIcon.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { TestCase } from "@playwright/test/reporter";
2+
3+
export const getTestStatusIcon = (tests: TestCase[]) => {
4+
const testOutcomes = tests.map((test) => {
5+
const lastResult = test.results[test.results.length - 1];
6+
return lastResult.status;
7+
});
8+
9+
if (
10+
testOutcomes.includes("failed") ||
11+
testOutcomes.includes("interrupted") ||
12+
testOutcomes.includes("timedOut")
13+
) {
14+
return "❌";
15+
} else if (testOutcomes.includes("skipped")) {
16+
return "⚠️";
17+
}
18+
19+
return "✅";
20+
};

tests/retry.spec.ts

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { test, expect, Page } from "@playwright/test";
2+
3+
test.describe("Test retry", () => {
4+
let page: Page;
5+
6+
test.beforeAll(async ({ browser }) => {
7+
page = await browser.newPage();
8+
9+
await page.goto("https://www.eliostruyf.com", {
10+
waitUntil: "domcontentloaded",
11+
});
12+
});
13+
14+
test.afterAll(async ({ browser }) => {
15+
await page.close();
16+
await browser.close();
17+
});
18+
19+
test("First test should fail, next should work", async ({}, testInfo) => {
20+
if (testInfo.retry === 0) {
21+
expect(true).toBeFalsy();
22+
}
23+
expect(true).toBeTruthy();
24+
});
25+
26+
test("Skip the test", async () => {
27+
test.skip(true, "Don't need to test this.");
28+
});
29+
30+
test("Should work fine", async () => {
31+
expect(true).toBeTruthy();
32+
});
33+
});

0 commit comments

Comments
 (0)