From 10c6c229a676d32466c1dff4d67e02197dd4dd1f Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sun, 8 Dec 2024 20:14:47 +0000 Subject: [PATCH 1/3] fix: cli args prefixed ctrfJson --- src/generate-report.ts | 112 +++++++++++++++++++++++------------------ 1 file changed, 64 insertions(+), 48 deletions(-) diff --git a/src/generate-report.ts b/src/generate-report.ts index 09423a8..6a0c265 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -26,6 +26,24 @@ interface ReporterConfigOptions { repositoryUrl?: string branchName?: string testEnvironment?: string + + // CLI-prefixed options + ctrfJsonOutputFile?: string + ctrfJsonOutputDir?: string + ctrfJsonMinimal?: boolean + ctrfJsonTestType?: string + ctrfJsonAppName?: string + ctrfJsonAppVersion?: string + ctrfJsonOsPlatform?: string + ctrfJsonOsRelease?: string + ctrfJsonOsVersion?: string + ctrfJsonBuildName?: string + ctrfJsonBuildNumber?: string + ctrfJsonBuildUrl?: string + ctrfJsonRepositoryName?: string + ctrfJsonRepositoryUrl?: string + ctrfJsonBranchName?: string + ctrfJsonTestEnvironment?: string } class GenerateCtrfReport { @@ -43,53 +61,26 @@ class GenerateCtrfReport { private readonly collectionRunOptions: NewmanRunOptions ) { this.registerEvents() + const normalizedOptions = this.normalizeOptions(reporterOptions) + console.log('Normalized Options:', JSON.stringify(normalizedOptions)) this.reporterConfigOptions = { - outputFile: - reporterOptions?.outputFile ?? - reporterOptions?.outputFile ?? - this.defaultOutputFile, - outputDir: - reporterOptions?.outputDir ?? - reporterOptions?.outputDir ?? - this.defaultOutputDir, - minimal: this.parseBoolean( - reporterOptions?.minimal ?? reporterOptions?.minimal ?? 'false' - ), - testType: - reporterOptions?.testType ?? reporterOptions?.testType ?? undefined, - appName: - reporterOptions?.appName ?? reporterOptions?.appName ?? undefined, - appVersion: - reporterOptions?.appVersion ?? reporterOptions?.appVersion ?? undefined, - osPlatform: - reporterOptions?.osPlatform ?? reporterOptions?.osPlatform ?? undefined, - osRelease: - reporterOptions?.osRelease ?? reporterOptions?.osRelease ?? undefined, - osVersion: - reporterOptions?.osVersion ?? reporterOptions?.osVersion ?? undefined, - buildName: - reporterOptions?.buildName ?? reporterOptions?.buildName ?? undefined, - buildNumber: - reporterOptions?.buildNumber ?? - reporterOptions?.buildNumber ?? - undefined, - buildUrl: - reporterOptions?.buildUrl ?? reporterOptions?.buildUrl ?? undefined, - repositoryName: - reporterOptions?.repositoryName ?? - reporterOptions?.repositoryName ?? - undefined, - repositoryUrl: - reporterOptions?.repositoryUrl ?? - reporterOptions?.repositoryUrl ?? - undefined, - branchName: - reporterOptions?.branchName ?? reporterOptions?.branchName ?? undefined, - testEnvironment: - reporterOptions?.testEnvironment ?? - reporterOptions?.testEnvironment ?? - undefined, + outputFile: normalizedOptions.outputFile ?? this.defaultOutputFile, + outputDir: normalizedOptions.outputDir ?? this.defaultOutputDir, + minimal: this.parseBoolean(normalizedOptions.minimal ?? 'false'), + testType: normalizedOptions.testType, + appName: normalizedOptions.appName, + appVersion: normalizedOptions.appVersion, + osPlatform: normalizedOptions.osPlatform, + osRelease: normalizedOptions.osRelease, + osVersion: normalizedOptions.osVersion, + buildName: normalizedOptions.buildName, + buildNumber: normalizedOptions.buildNumber, + buildUrl: normalizedOptions.buildUrl, + repositoryName: normalizedOptions.repositoryName, + repositoryUrl: normalizedOptions.repositoryUrl, + branchName: normalizedOptions.branchName, + testEnvironment: normalizedOptions.testEnvironment, } this.ctrfReport = { @@ -189,6 +180,34 @@ class GenerateCtrfReport { }) } + private normalizeOptions( + options: ReporterConfigOptions + ): ReporterConfigOptions { + const normalized: ReporterConfigOptions = {} + + normalized.outputFile = options.outputFile ?? options.ctrfJsonOutputFile + normalized.outputDir = options.outputDir ?? options.ctrfJsonOutputDir + normalized.minimal = options.minimal ?? options.ctrfJsonMinimal + normalized.testType = options.testType ?? options.ctrfJsonTestType + normalized.appName = options.appName ?? options.ctrfJsonAppName + normalized.appVersion = options.appVersion ?? options.ctrfJsonAppVersion + normalized.osPlatform = options.osPlatform ?? options.ctrfJsonOsPlatform + normalized.osRelease = options.osRelease ?? options.ctrfJsonOsRelease + normalized.osVersion = options.osVersion ?? options.ctrfJsonOsVersion + normalized.buildName = options.buildName ?? options.ctrfJsonBuildName + normalized.buildNumber = options.buildNumber ?? options.ctrfJsonBuildNumber + normalized.buildUrl = options.buildUrl ?? options.ctrfJsonBuildUrl + normalized.repositoryName = + options.repositoryName ?? options.ctrfJsonRepositoryName + normalized.repositoryUrl = + options.repositoryUrl ?? options.ctrfJsonRepositoryUrl + normalized.branchName = options.branchName ?? options.ctrfJsonBranchName + normalized.testEnvironment = + options.testEnvironment ?? options.ctrfJsonTestEnvironment + + return normalized + } + private setFilename(filename: string): void { if (filename.endsWith('.json')) { this.filename = filename @@ -222,9 +241,6 @@ class GenerateCtrfReport { if (reporterConfigOptions.buildUrl !== undefined) { this.ctrfEnvironment.buildUrl = reporterConfigOptions.buildUrl } - if (reporterConfigOptions.buildUrl !== undefined) { - this.ctrfEnvironment.buildUrl = reporterConfigOptions.buildUrl - } if (reporterConfigOptions.repositoryName !== undefined) { this.ctrfEnvironment.repositoryName = reporterConfigOptions.repositoryName } From 62e5ce6b8339d8ad69df44983e5a1239ce4f161f Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sun, 8 Dec 2024 20:18:47 +0000 Subject: [PATCH 2/3] chore: increment version --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 66a9ec4..e88d0e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "newman-reporter-ctrf-json", - "version": "0.0.7", + "version": "0.0.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "newman-reporter-ctrf-json", - "version": "0.0.7", + "version": "0.0.8", "license": "MIT", "devDependencies": { "@types/newman": "^5.3.5", From 0fb98218d1b9b902987d560879d7378a25ee3f4f Mon Sep 17 00:00:00 2001 From: Matthew Thomas Date: Sun, 8 Dec 2024 20:21:28 +0000 Subject: [PATCH 3/3] chore: increment version --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index bd73e85..8ecb204 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "newman-reporter-ctrf-json", - "version": "0.0.7", - "description": "Create a common JSON test report for Postman Newman tests", + "version": "0.0.8", + "description": "A Postman Newman JSON test reporter to create test results reports", "main": "dist/index.js", "scripts": { "build": "tsc",