Skip to content

Commit

Permalink
Merge pull request #18 from estruyf/dev
Browse files Browse the repository at this point in the history
Hide passing tests from the reporter #17
  • Loading branch information
estruyf authored Aug 7, 2024
2 parents 89ac223 + 51f3098 commit f2080bc
Show file tree
Hide file tree
Showing 20 changed files with 511 additions and 155 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.9.0]

- [#17](https://github.com/estruyf/playwright-github-actions-reporter/issues/17): Added the ability to define which types of test results should be shown in the summary

## [1.8.0]

- Added `⏭️` icon for skipped tests
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,18 @@ The reporter supports the following configuration options:
| showAnnotations | Show annotations from tests | `true` |
| showTags | Show tags from tests | `true` |
| showError | Show error message in summary | `false` |
| includeResults | Define which types of test results should be shown in the summary | `['pass', 'skipped', 'fail', 'flaky']` |
| quiet | Do not show any output in the console | `false` |

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

```ts
import { defineConfig } from '@playwright/test';
import type { GitHubActionOptions } from '@estruyf/github-actions-reporter';

export default defineConfig({
reporter: [
['@estruyf/github-actions-reporter', {
['@estruyf/github-actions-reporter', <GitHubActionOptions>{
title: 'My custom title',
useDetails: true,
showError: true
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.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "@estruyf/github-actions-reporter",
"version": "1.8.0",
"version": "1.9.0",
"description": "GitHub Actions reporter for Playwright",
"main": "dist/index.js",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "NODE_ENV=development npx playwright test",
"test:local": "act -j testing -P ubuntu-latest=catthehacker/ubuntu:act-latest --container-architecture linux/amd64 --env GITHUB_STEP_SUMMARY='/dev/stdout'",
"test:jest": "jest --coverage --coverageDirectory=../coverage"
},
"author": "Elio Struyf <[email protected]>",
Expand Down
26 changes: 23 additions & 3 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { GitHubActionOptions } from "./src/models/GitHubActionOptions";
import { PlaywrightTestConfig, defineConfig, devices } from "@playwright/test";

const config: PlaywrightTestConfig<{}, {}> = {
Expand All @@ -14,14 +15,33 @@ const config: PlaywrightTestConfig<{}, {}> = {
// ["list"],
[
"./src/index.ts",
{
title: "Reporter testing",
<GitHubActionOptions>{
title: "Reporter (details: false, report: fail, flaky, skipped)",
useDetails: false,
showError: true,
quiet: false,
includeResults: ["fail", "flaky", "skipped"],
},
],
[
"./src/index.ts",
<GitHubActionOptions>{
title: "Reporter (details: false, report: pass, skipped)",
useDetails: false,
showError: true,
quiet: false,
includeResults: ["pass", "skipped"],
},
],
[
"./src/index.ts",
<GitHubActionOptions>{
title: "Reporter (details: true, report: fail, flaky, skipped)",
useDetails: true,
quiet: true,
includeResults: ["fail", "flaky", "skipped"],
},
],
["./src/index.ts", { useDetails: true, quiet: true }],
],
use: {
actionTimeout: 0,
Expand Down
14 changes: 5 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ import type {
TestResult,
} from "@playwright/test/reporter";
import { processResults } from "./utils/processResults";

export interface GitHubActionOptions {
title?: string;
useDetails?: boolean;
showAnnotations: boolean;
showTags: boolean;
showError?: boolean;
quiet?: boolean;
}
import { GitHubActionOptions } from "./models";

class GitHubAction implements Reporter {
private suite: Suite | undefined;
Expand All @@ -39,6 +31,10 @@ class GitHubAction implements Reporter {
this.options.showTags = true;
}

if (typeof options.includeResults === "undefined") {
this.options.includeResults = ["fail", "flaky", "pass", "skipped"];
}

if (process.env.NODE_ENV === "development") {
console.log(`Using development mode`);
console.log(`Options: ${JSON.stringify(this.options, null, 2)}`);
Expand Down
1 change: 1 addition & 0 deletions src/models/DisplayLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type DisplayLevel = "pass" | "skipped" | "fail" | "flaky";
11 changes: 11 additions & 0 deletions src/models/GitHubActionOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { DisplayLevel } from ".";

export interface GitHubActionOptions {
title?: string;
useDetails?: boolean;
showAnnotations: boolean;
showTags: boolean;
showError?: boolean;
quiet?: boolean;
includeResults?: DisplayLevel[];
}
2 changes: 2 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./DisplayLevel";
export * from "./GitHubActionOptions";
146 changes: 118 additions & 28 deletions src/utils/getHtmlTable.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { DisplayLevel } from "../models";
import { getHtmlTable } from "./getHtmlTable";

const defaultDisplayLevel: DisplayLevel[] = [
"pass",
"fail",
"flaky",
"skipped",
];

describe("getHtmlTable", () => {
it("should return the HTML table with error column", async () => {
const tests: any = [
Expand Down Expand Up @@ -46,7 +54,13 @@ describe("getHtmlTable", () => {
},
];

const result = await getHtmlTable(tests, false, false, true);
const result = await getHtmlTable(
tests,
false,
false,
true,
defaultDisplayLevel
);

const expected = `
<br>
Expand Down Expand Up @@ -86,11 +100,59 @@ describe("getHtmlTable", () => {
</table>
`;

expect(result.trim()).toEqual(expected.trim());
expect(result?.trim()).toEqual(expected.trim());
});

it("should return an empty HTML table if tests is empty (without error column)", async () => {
const result = await getHtmlTable([], false, false, false);
it("should return the HTML table with error column (excluding passed tests)", async () => {
const tests: any = [
{
title: "Test 1",
results: [
{
status: "passed",
duration: 1000,
retry: 0,
error: null,
},
],
parent: {
title: "Parent Title",
},
},
{
title: "Test 2",
results: [
{
status: "failed",
duration: 2000,
retry: 1,
error: {
message: "Test failed",
},
},
],
parent: null,
},
{
title: "Test 3",
results: [
{
status: "failed",
duration: null,
retry: null,
error: {
message: "Test failed",
},
},
],
},
];

const result = await getHtmlTable(tests, false, false, true, [
"fail",
"flaky",
"skipped",
]);

const expected = `
<br>
Expand All @@ -101,37 +163,53 @@ describe("getHtmlTable", () => {
<th>Status</th>
<th>Duration</th>
<th>Retries</th>
<th>Error</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test 2</td>
<td>❌ Fail</td>
<td>2s</td>
<td>1</td>
<td>Test failed</td>
</tr>
<tr>
<td>Test 3</td>
<td>❌ Fail</td>
<td></td>
<td></td>
<td>Test failed</td>
</tr>
</tbody>
</table>
`;

expect(result.trim()).toEqual(expected.trim());
expect(result?.trim()).toEqual(expected.trim());
});

it("should return an empty HTML table if tests is empty (including error column)", async () => {
const result = await getHtmlTable([], false, false, true);
it("should not return a table when no tests are provided (without error column)", async () => {
const result = await getHtmlTable(
[],
false,
false,
false,
defaultDisplayLevel
);

const expected = `
<br>
<table role="table">
<thead>
<tr>
<th>Test</th>
<th>Status</th>
<th>Duration</th>
<th>Retries</th>
<th>Error</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
`;
expect(result).toBeUndefined();
});

it("should not return a table when no tests are provided (including error column)", async () => {
const result = await getHtmlTable(
[],
false,
false,
true,
defaultDisplayLevel
);

expect(result.trim()).toEqual(expected.trim());
expect(result).toBeUndefined();
});

it("should return the HTML table with annotations row", async () => {
Expand All @@ -158,7 +236,13 @@ describe("getHtmlTable", () => {
},
];

const result = await getHtmlTable(tests, true, false, false);
const result = await getHtmlTable(
tests,
true,
false,
false,
defaultDisplayLevel
);

const expected = `
<br>
Expand All @@ -184,7 +268,7 @@ describe("getHtmlTable", () => {
</tbody>
</table>`;

expect(result.trim()).toEqual(expected.trim());
expect(result?.trim()).toEqual(expected.trim());
});

it("should return the HTML table with annotations and tags columns", async () => {
Expand Down Expand Up @@ -226,7 +310,13 @@ describe("getHtmlTable", () => {
},
];

const result = await getHtmlTable(tests, true, true, true);
const result = await getHtmlTable(
tests,
true,
true,
true,
defaultDisplayLevel
);

const expected = `
<br>
Expand Down Expand Up @@ -264,6 +354,6 @@ describe("getHtmlTable", () => {
</tbody>
</table>`;

expect(result.trim()).toEqual(expected.trim());
expect(result?.trim()).toEqual(expected.trim());
});
});
Loading

0 comments on commit f2080bc

Please sign in to comment.