Skip to content

Commit

Permalink
Merge pull request #11 from ctrf-io/feat/build-url
Browse files Browse the repository at this point in the history
feat: add optional test environment properties
  • Loading branch information
Ma11hewThomas authored Jul 30, 2024
2 parents 28a0eaa + 6db6ae6 commit 2fa48e0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
}
},

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mocha-ctrf-json-reporter",
"version": "0.0.4",
"version": "0.0.6",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand All @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion types/ctrf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<string, any>
}

Expand Down

0 comments on commit 2fa48e0

Please sign in to comment.