From 2503825c970b89997b7b66c8a947a218484226c4 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sun, 23 Mar 2025 17:46:14 +0000 Subject: [PATCH 1/2] feat: add attachments, stdout, stderr --- README.md | 52 +++++++++++++++++++++++------------------- package-lock.json | 4 ++-- package.json | 3 ++- src/generate-report.ts | 20 ++++++++++++++++ types/ctrf.d.ts | 10 +++++++- 5 files changed, 61 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index e4923da..298fc8c 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,6 @@ > Save Playwright test results as a JSON file -![Static Badge](https://img.shields.io/badge/official-red?label=ctrf&labelColor=green) -[![build](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml/badge.svg)](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml) -![NPM Downloads](https://img.shields.io/npm/d18m/playwright-ctrf-json-reporter?logo=npm) -![npm bundle size](https://img.shields.io/bundlephobia/minzip/playwright-ctrf-json-reporter?label=Size) -![GitHub Repo stars](https://img.shields.io/github/stars/ctrf-io/playwright-ctrf-json-report) A Playwright JSON test reporter to create test reports that follow the CTRF standard. @@ -36,6 +31,11 @@ Explore more integrations ## Features +![Static Badge](https://img.shields.io/badge/official-red?label=ctrf&labelColor=green) +[![build](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml/badge.svg)](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml) +![NPM Downloads](https://img.shields.io/npm/d18m/playwright-ctrf-json-reporter?logo=npm) +![npm bundle size](https://img.shields.io/bundlephobia/minzip/playwright-ctrf-json-reporter?label=Size) +![GitHub Repo stars](https://img.shields.io/github/stars/ctrf-io/playwright-ctrf-json-report) - Generate JSON test reports that are [CTRF](https://ctrf.io) compliant - Customizable output options, minimal or comprehensive reports @@ -146,25 +146,29 @@ Replace directory with the path to the directory containing the CTRF reports you The test object in the report includes the following [CTRF properties](https://ctrf.io/docs/schema/test): -| Name | Type | Required | Details | -| ------------ | ---------------- | -------- | ----------------------------------------------------------------------------------- | -| `name` | String | Required | The name of the test. | -| `status` | String | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. | -| `duration` | Number | Required | The time taken for the test execution, in milliseconds. | -| `start` | Number | Optional | The start time of the test as a Unix epoch timestamp. | -| `stop` | Number | Optional | The end time of the test as a Unix epoch timestamp. | -| `suite` | String | Optional | The suite or group to which the test belongs. | -| `message` | String | Optional | The failure message if the test failed. | -| `trace` | String | Optional | The stack trace captured if the test failed. | -| `rawStatus` | String | Optional | The original playwright status of the test before mapping to CTRF status. | -| `tags` | Array of Strings | Optional | The tags retrieved from the test name | -| `type` | String | Optional | The type of test (e.g., `api`, `e2e`). | -| `filepath` | String | Optional | The file path where the test is located in the project. | -| `retries` | Number | Optional | The number of retries attempted for the test. | -| `flaky` | Boolean | Optional | Indicates whether the test result is flaky. | -| `browser` | String | Optional | The browser used for the test. | -| `screenshot` | String | Optional | A base64 encoded screenshot taken during the test. | -| `steps` | Array of Objects | Optional | Individual steps in the test, especially for BDD-style testing. | +| Name | Type | Required | Details | +| ------------- | ---------------- | -------- | ----------------------------------------------------------------------------------- | +| `name` | String | Required | The name of the test. | +| `status` | String | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. | +| `duration` | Number | Required | The time taken for the test execution, in milliseconds. | +| `start` | Number | Optional | The start time of the test as a Unix epoch timestamp. | +| `stop` | Number | Optional | The end time of the test as a Unix epoch timestamp. | +| `suite` | String | Optional | The suite or group to which the test belongs. | +| `message` | String | Optional | The failure message if the test failed. | +| `trace` | String | Optional | The stack trace captured if the test failed. | +| `rawStatus` | String | Optional | The original playwright status of the test before mapping to CTRF status. | +| `tags` | Array of Strings | Optional | The tags retrieved from the test name | +| `type` | String | Optional | The type of test (e.g., `api`, `e2e`). | +| `filepath` | String | Optional | The file path where the test is located in the project. | +| `retries` | Number | Optional | The number of retries attempted for the test. | +| `flaky` | Boolean | Optional | Indicates whether the test result is flaky. | +| `browser` | String | Optional | The browser used for the test. | +| `attachments` | Array of Objects | Optional | The attachments attached to the test. | +| `stdout` | Array of Strings | Optional | The standard output of the test. | +| `stderr` | Array of Strings | Optional | The standard error of the test. | +| `screenshot` | String | Optional | A base64 encoded screenshot taken during the test. | +| `screenshot` | String | Optional | A base64 encoded screenshot taken during the test. | +| `steps` | Array of Objects | Optional | Individual steps in the test, especially for BDD-style testing. | ## Advanced usage diff --git a/package-lock.json b/package-lock.json index 43a25e0..40bb851 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "playwright-ctrf-json-reporter", - "version": "0.0.18", + "version": "0.0.19", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "playwright-ctrf-json-reporter", - "version": "0.0.18", + "version": "0.0.19", "license": "MIT", "devDependencies": { "@playwright/test": "^1.39.0", diff --git a/package.json b/package.json index 95d6a09..72c1e1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "playwright-ctrf-json-reporter", - "version": "0.0.18", + "version": "0.0.19", "description": "A Playwright JSON test reporter to create test results reports", "main": "dist/index.js", "scripts": { @@ -12,6 +12,7 @@ "format-check": "prettier --check ." }, "repository": "github:ctrf-io/playwright-ctrf-json-report", + "homepage": "https://ctrf.io", "files": [ "dist/", "README.md" diff --git a/src/generate-report.ts b/src/generate-report.ts index b14c7db..a7463c8 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -15,6 +15,7 @@ import { type CtrfReport, type CtrfTest, type CtrfEnvironment, + type CtrfAttachment, } from '../types/ctrf' interface ReporterConfigOptions { @@ -206,6 +207,13 @@ class GenerateCtrfReport implements Reporter { ) test.browser = `${this.extractMetadata(testResult) ?.name} ${this.extractMetadata(testResult)?.version}` + test.attachments = this.filterValidAttachments(testResult.attachments) + test.stdout = testResult.stdout.map((item) => + Buffer.isBuffer(item) ? item.toString() : String(item) + ) + test.stderr = testResult.stderr.map((item) => + Buffer.isBuffer(item) ? item.toString() : String(item) + ) if (this.reporterConfigOptions.annotations !== undefined) { test.extra = { annotations: testCase.annotations } } @@ -423,6 +431,18 @@ class GenerateCtrfReport implements Reporter { }) } } + + filterValidAttachments( + attachments: TestResult['attachments'] + ): CtrfAttachment[] { + return attachments + .filter((attachment) => attachment.path !== undefined) + .map((attachment) => ({ + name: attachment.name, + contentType: attachment.contentType, + path: attachment.path ?? '', + })) + } } export default GenerateCtrfReport diff --git a/types/ctrf.d.ts b/types/ctrf.d.ts index 61a72c6..54eb865 100644 --- a/types/ctrf.d.ts +++ b/types/ctrf.d.ts @@ -38,7 +38,9 @@ export interface CtrfTest { filePath?: string retries?: number flaky?: boolean - attempts?: CtrfTest[] + attachments?: CtrfAttachment[] + stdout?: string[] + stderr?: string[] browser?: string device?: string screenshot?: string @@ -74,6 +76,12 @@ export interface Step { status: CtrfTestState } +export interface CtrfAttachment { + name: string + contentType: string + path: string +} + export type CtrfTestState = | 'passed' | 'failed' From 4f206136c63ddd0f1e66cb75e9f9500385f9dc02 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sun, 23 Mar 2025 17:51:47 +0000 Subject: [PATCH 2/2] docs: format --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 298fc8c..00ee491 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ > Save Playwright test results as a JSON file - A Playwright JSON test reporter to create test reports that follow the CTRF standard. [Common Test Report Format](https://ctrf.io) ensures the generation of uniform JSON test reports, independent of programming languages or test framework in use. @@ -31,6 +30,7 @@ Explore more integrations ## Features + ![Static Badge](https://img.shields.io/badge/official-red?label=ctrf&labelColor=green) [![build](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml/badge.svg)](https://github.com/ctrf-io/playwright-ctrf-json-report/actions/workflows/main.yaml) ![NPM Downloads](https://img.shields.io/npm/d18m/playwright-ctrf-json-reporter?logo=npm)