Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat separate message from stack trace #12

Merged

Conversation

an-ky
Copy link
Contributor

@an-ky an-ky commented Jun 6, 2024

The CTRF Test objects has a message and a trace attribute. According to
the documentation, the message should contain a description of the test
result and the trace should contain the stack trace of a failed test.

The reporter receives the assertion description and the stack trace
intermingled and stores them both, redundantly, in the message and trace
attributes.

This change splits the assert description from the stack trace as shown
stores them separately. Everything above the dashed line is stored in
message while lines below are stored in trace.

```
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

@@ -23,11 +23,11 @@
          "isSelected": true,
        },
      ],
      "damper_setup": "damper_1,damper_2",
      "driver": "driver1",
-     "id": 0,
+     "id": 1,
      "isCurrentlyUsedInProfile": true,
      "isIntermediateState": true,
      "isSelectedForAll": false,
      "lap": "LapName1",
      "lap_id": 1,
-------------------------
    at lap-channel-type-table-data-creation.service.spec.ts:185:26
    at zone-testing-bundle.umd.js:409:30)
    at zone-testing-bundle.umd.js:3830:43)
    at zone.js/bundles/zone-testing-bundle.umd.js:408:56)
```

This simplifies processing of both values for later tools when eval-
uating the test results.

Note: I'm totally new to TypeScript, got a short introduction from my co-worker today to be able to start this. Hints on style are welcome, therefore.

jasmin.metschl and others added 3 commits June 6, 2024 14:46
The CTRF Test objects has a message and a trace attribute. According to
the documentation, the message should contain a description of the test
result and the trace should contain the stack trace of a failed test.

The reporter receives the assertion description and the stack trace
intermingled and stores them both, redundantly, in the message and trace
attributes.

This change splits the assert description from the stack trace as shown
stores them separately. Everything above the dashed line is stored in
message while lines below are stored in trace.

```
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

@@ -23,11 +23,11 @@
          "isSelected": true,
        },
      ],
      "damper_setup": "damper_1,damper_2",
      "driver": "driver1",
-     "id": 0,
+     "id": 1,
      "isCurrentlyUsedInProfile": true,
      "isIntermediateState": true,
      "isSelectedForAll": false,
      "lap": "LapName1",
      "lap_id": 1,
-------------------------
    at lap-channel-type-table-data-creation.service.spec.ts:185:26
    at zone-testing-bundle.umd.js:409:30)
    at zone-testing-bundle.umd.js:3830:43)
    at zone.js/bundles/zone-testing-bundle.umd.js:408:56)
```

This simplifies processing of both values for later tools when eval-
uating the test results.
// slice message until stack trace part is found and remove ansi color codes
failureDetails.message = joinedMessages.slice(0, match?.index).replace(colorCodesPattern, '')

// slice from begin of stack trace, remove indentation of each line and return the trace as string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

failureDetails.message = testResult.failureMessages.join('\r\n')
const joinedMessages = testResult.failureMessages.join('\n')
const match = joinedMessages.match(messageStackTracePattern)
// slice message until stack trace part is found and remove ansi color codes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

@@ -148,16 +149,26 @@ class GenerateCtrfReport implements Reporter {
}

extractFailureDetails(testResult: AssertionResult): Partial<CtrfTest> {
const messageStackTracePattern = /^\s{4}at/mu
const colorCodesPattern = /\x1b\[\d+m/gmu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable eslint for this line by adding below comment to line above.

// eslint-disable-next-line no-control-regex

Dealing with ANSI escape codes for coloring text in terminal outputs is a valid use case.

@Ma11hewThomas
Copy link
Collaborator

Great work for your first contribution in typescript!

Please run the following static analysis checks -
npm run format
npm run lint

@an-ky an-ky requested a review from Ma11hewThomas June 7, 2024 21:03
@Ma11hewThomas Ma11hewThomas merged commit 736a66c into ctrf-io:main Jun 7, 2024
1 check passed
@an-ky an-ky deleted the feat--separate-message-from-stack-trace branch June 10, 2024 07:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants