Skip to content

Commit

Permalink
feat: add suite type
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma11hewThomas committed Aug 6, 2024
1 parent 1c0e532 commit 5d46fe3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
18 changes: 18 additions & 0 deletions src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -116,6 +120,8 @@ class GenerateCtrfReport {
return
}

const collectionName = summary.collection.name

if (
this.reporterConfigOptions?.ctrfJsonOutputFile !== undefined &&
this.reporterConfigOptions.ctrfJsonOutputFile !== ''
Expand All @@ -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
}
Expand Down Expand Up @@ -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

0 comments on commit 5d46fe3

Please sign in to comment.