Skip to content

Commit

Permalink
feat: add various test properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma11hewThomas committed Jun 19, 2024
1 parent 42f3a81 commit 29a5f89
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
41 changes: 23 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ The only way we can grow CTRF is with your help and the support of the software
- Generate JSON test reports that are [CTRF](https://ctrf.io) compliant
- Straightforward integration with Mocha


```json
{
"results": {
Expand Down Expand Up @@ -66,16 +65,6 @@ The only way we can grow CTRF is with your help and the support of the software
}
```

## What is CTRF?

CTRF is a universal JSON test report schema that addresses the lack of a standardized format for JSON test reports.

**Consistency Across Tools:** Different testing tools and frameworks often produce reports in varied formats. CTRF ensures a uniform structure, making it easier to understand and compare reports, regardless of the testing tool used.

**Language and Framework Agnostic:** It provides a universal reporting schema that works seamlessly with any programming language and testing framework.

**Facilitates Better Analysis:** With a standardized format, programatically analyzing test outcomes across multiple platforms becomes more straightforward.

## Installation

```bash
Expand Down Expand Up @@ -157,13 +146,29 @@ npx mocha --reporter mocha-ctrf-json-reporter --reporter-options "outputFile=cus

The test object in the report includes the following [CTRF properties](https://ctrf.io/docs/schema/test):

| Name | Type | Required | Details |
| ---------- | ------ | -------- | ----------------------------------------------------------------------------------- |
| `name` | String | Required | The name of the test. |
| `status` | String | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. |
| `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. |
| Name | Type | Required | Details |
| ----------- | ------- | -------- | ----------------------------------------------------------------------------------- |
| `name` | String | Required | The name of the test. |
| `status` | String | Required | The outcome of the test. One of: `passed`, `failed`, `skipped`, `pending`, `other`. |
| `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. |
| `start` | Number | Optional | The start time of the test as a Unix epoch timestamp. |
| `stop` | Number | Optional | The end time of the test as a Unix epoch timestamp. |
| `rawStatus` | String | Optional | The original playwright status of the test before mapping to CTRF status. |
| `filePath` | String | Optional | The file path where the test is located in the project. |
| `retries` | Number | Optional | The number of retries attempted for the test. |
| `flaky` | Boolean | Optional | Indicates whether the test result is flaky. |

## What is CTRF?

CTRF is a universal JSON test report schema that addresses the lack of a standardized format for JSON test reports.

**Consistency Across Tools:** Different testing tools and frameworks often produce reports in varied formats. CTRF ensures a uniform structure, making it easier to understand and compare reports, regardless of the testing tool used.

**Language and Framework Agnostic:** It provides a universal reporting schema that works seamlessly with any programming language and testing framework.

**Facilitates Better Analysis:** With a standardized format, programatically analyzing test outcomes across multiple platforms becomes more straightforward.

## Support Us

Expand Down
4 changes: 2 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.3",
"version": "0.0.4",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand All @@ -15,7 +15,7 @@
"dist/",
"README.md"
],
"author": "",
"author": "Matthew Thomas",
"license": "ISC",
"devDependencies": {
"@types/mocha": "^10.0.3",
Expand Down
12 changes: 12 additions & 0 deletions src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,21 @@ class GenerateCtrfReport extends reporters.Base {
ctrfReport: CtrfReport
): void {
const status = testCase.state ?? 'other'
const endTime = Date.now()
const duration = testCase.duration ?? 0
const startTime = endTime - duration
const currentRetry = (testCase as any).currentRetry()

const test: CtrfTest = {
name: testCase.fullTitle(),
status,
duration: testCase.duration ?? 0,
retries: currentRetry,
flaky: testCase.state === 'passed' && currentRetry > 0,
filePath: testCase.file,
rawStatus: testCase.state,
start: startTime,
stop: Date.now(),
}

if (testCase.state === 'failed' && testCase.err != null) {
Expand Down Expand Up @@ -247,4 +258,5 @@ class GenerateCtrfReport extends reporters.Base {
}
}
}

export = GenerateCtrfReport
4 changes: 2 additions & 2 deletions types/ctrf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export interface CtrfTest {
tags?: string[]
type?: string
filePath?: string
retry?: number
flake?: boolean
retries?: number
flaky?: boolean
attempts?: CtrfTest[]
browser?: string
device?: string
Expand Down

0 comments on commit 29a5f89

Please sign in to comment.