From 6db6ae6ccf2f9e812d049d5592dda115db070e36 Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Tue, 30 Jul 2024 17:58:57 +0100 Subject: [PATCH] feat: add optional test environment properties --- README.md | 6 ++++++ package.json | 5 +++-- src/generate-report.ts | 26 ++++++++++++++++++++++++++ types/ctrf.d.ts | 7 ++++++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d772311..d5b793e 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,12 @@ The reporter supports several configuration options, update your .mocharc.js osVersion: '5.4.0', // Optional: Specify the OS version. buildName: 'MyApp Build', // Optional: Specify the build name. buildNumber: '100', // Optional: Specify the build number. + buildName: 'MyApp Build', // Optional: Specify the build name. + buildUrl: "https://ctrf.io", // Optional: Specify the build url. + repositoryName: "ctrf-json", // Optional: Specify the repository name. + repositoryUrl: "https://gh.io", // Optional: Specify the repository url. + branchName: "main", // Optional: Specify the branch name. + testEnvironment: "staging" // Optional: Specify the test environment (e.g. staging, production). } }, diff --git a/package.json b/package.json index 769fc6d..17cc346 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mocha-ctrf-json-reporter", - "version": "0.0.4", + "version": "0.0.6", "description": "", "main": "dist/index.js", "scripts": { @@ -11,12 +11,13 @@ "format": "prettier --write .", "format-check": "prettier --check ." }, + "repository": "github:ctrf-io/mocha-ctrf-json-reporter", "files": [ "dist/", "README.md" ], "author": "Matthew Thomas", - "license": "ISC", + "license": "MIT", "devDependencies": { "@types/mocha": "^10.0.3", "@types/node": "^20.8.7", diff --git a/src/generate-report.ts b/src/generate-report.ts index 1c00993..71fe0f8 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -26,6 +26,11 @@ interface ReporterOptions { osVersion?: string | undefined buildName?: string | undefined buildNumber?: string | undefined + buildUrl?: string | undefined + repositoryName?: string | undefined + repositoryUrl?: string | undefined + branchName?: string | undefined + testEnvironment?: string | undefined } class GenerateCtrfReport extends reporters.Base { @@ -53,6 +58,11 @@ class GenerateCtrfReport extends reporters.Base { osVersion: this.reporterOptions?.osVersion ?? undefined, buildName: this.reporterOptions?.buildName ?? undefined, buildNumber: this.reporterOptions?.buildNumber ?? undefined, + buildUrl: this.reporterOptions?.buildUrl ?? undefined, + repositoryName: this.reporterOptions?.repositoryName ?? undefined, + repositoryUrl: this.reporterOptions?.repositoryUrl ?? undefined, + branchName: this.reporterOptions?.branchName ?? undefined, + testEnvironment: this.reporterOptions?.testEnvironment ?? undefined, } this.ctrfReport = { @@ -220,6 +230,22 @@ class GenerateCtrfReport extends reporters.Base { if (reporterConfigOptions.buildNumber !== undefined) { this.ctrfEnvironment.buildNumber = reporterConfigOptions.buildNumber } + if (reporterConfigOptions.buildUrl !== undefined) { + this.ctrfEnvironment.buildUrl = reporterConfigOptions.buildUrl + } + if (reporterConfigOptions.repositoryName !== undefined) { + this.ctrfEnvironment.repositoryName = reporterConfigOptions.repositoryName + } + if (reporterConfigOptions.repositoryUrl !== undefined) { + this.ctrfEnvironment.repositoryUrl = reporterConfigOptions.repositoryUrl + } + if (reporterConfigOptions.branchName !== undefined) { + this.ctrfEnvironment.branchName = reporterConfigOptions.branchName + } + if (reporterConfigOptions.testEnvironment !== undefined) { + this.ctrfEnvironment.testEnvironment = + reporterConfigOptions.testEnvironment + } } private hasEnvironmentDetails(environment: CtrfEnvironment): boolean { diff --git a/types/ctrf.d.ts b/types/ctrf.d.ts index d34de57..a45b82e 100644 --- a/types/ctrf.d.ts +++ b/types/ctrf.d.ts @@ -32,13 +32,13 @@ export interface CtrfTest { suite?: string message?: string trace?: string + line?: number rawStatus?: string tags?: string[] type?: string filePath?: string retries?: number flaky?: boolean - attempts?: CtrfTest[] browser?: string device?: string screenshot?: string @@ -55,6 +55,11 @@ export interface CtrfEnvironment { osVersion?: string buildName?: string buildNumber?: string + buildUrl?: string + repositoryName?: string + repositoryUrl?: string + branchName?: string + testEnvironment?: string extra?: Record }