diff --git a/README.md b/README.md index 849c842..f043853 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ The reporter supports several configuration options passed via the command line: newman run ./postman_collection.json -r ctrf-json \ --reporter-ctrf-json-output-file custom-name.json \ --reporter-ctrf-json-output-dir custom-directory \ +--reporter-ctrf-json-test-type api \ +--reporter-ctrf-json-minimal false \ --reporter-ctrf-json-app-name MyApp \ --reporter-ctrf-json-app-version 1.0.0 \ --reporter-ctrf-json-os-platform linux \ @@ -106,6 +108,8 @@ The test object in the report includes the following [CTRF properties](https://c | `duration` | Number | Required | The time taken for the test execution, in milliseconds. | | `message` | String | Optional | The failure message if the test failed. | | `trace` | String | Optional | The stack trace captured if the test failed. | +| `suite` | String | Optional | The suite or group to which the test belongs. | +| `type` | String | Optional | The type of test (e.g., `api`, `contract`). | ## Support Us diff --git a/package-lock.json b/package-lock.json index bc6f0d2..4e2cc91 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "newman-reporter-ctrf-json", - "version": "0.0.5", + "version": "0.0.6", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "newman-reporter-ctrf-json", - "version": "0.0.5", + "version": "0.0.6", "license": "MIT", "devDependencies": { "@types/newman": "^5.3.5", diff --git a/package.json b/package.json index 476044b..bc2b637 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-ctrf-json", - "version": "0.0.5", + "version": "0.0.6", "description": "Create a common JSON test report for Postman Newman tests", "main": "dist/index.js", "scripts": { diff --git a/src/generate-report.ts b/src/generate-report.ts index 6735baa..5ed0615 100644 --- a/src/generate-report.ts +++ b/src/generate-report.ts @@ -49,6 +49,10 @@ class GenerateCtrfReport { reporterOptions?.ctrfJsonOutputFile ?? this.defaultOutputFile, ctrfJsonOutputDir: reporterOptions?.ctrfJsonOutputDir ?? this.defaultOutputDir, + ctrfJsonMinimal: this.parseBoolean( + reporterOptions?.ctrfJsonMinimal ?? 'false' + ), + ctrfJsonTestType: reporterOptions?.ctrfJsonTestType ?? 'api', ctrfJsonAppName: reporterOptions?.ctrfJsonAppName ?? undefined, ctrfJsonAppVersion: reporterOptions?.ctrfJsonAppVersion ?? undefined, ctrfJsonOsPlatform: reporterOptions?.ctrfJsonOsPlatform ?? undefined, @@ -116,6 +120,8 @@ class GenerateCtrfReport { return } + const collectionName = summary.collection.name + if ( this.reporterConfigOptions?.ctrfJsonOutputFile !== undefined && this.reporterConfigOptions.ctrfJsonOutputFile !== '' @@ -137,10 +143,17 @@ class GenerateCtrfReport { duration: execution.response.responseTime, } + if (this.reporterConfigOptions.ctrfJsonMinimal === false) { + testResult.suite = `${collectionName} > ${execution.item.name}` + testResult.type = this.reporterConfigOptions.ctrfJsonTestType + } + if (assertion.error != null) { testResult.message = assertion.error.message testResult.trace = assertion.error.stack this.ctrfReport.results.summary.failed += 1 + } else if (assertion.skipped) { + this.ctrfReport.results.summary.skipped += 1 } else { this.ctrfReport.results.summary.passed += 1 } @@ -229,6 +242,11 @@ class GenerateCtrfReport { console.error(`Error writing ctrf json report:, ${String(error)}`) } } + + private parseBoolean(value: string | boolean): boolean { + if (typeof value === 'boolean') return value + return value.toLowerCase() === 'true' + } } export = GenerateCtrfReport