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

fix: handling of AssertionResult.failureDetails #13

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
failureDetails.message = joinedMessages
.slice(0, match?.index)
.replace(colorCodesPattern, '')

Check failure on line 177 in src/generate-report.ts

View workflow job for this annotation

GitHub Actions / build

Delete `········`
failureDetails.trace = joinedMessages
.slice(match?.index)
.split('\n')
Expand All @@ -184,7 +185,7 @@
}

if (testResult.failureDetails !== undefined) {
failureDetails.trace = testResult.failureMessages.join('\r\n')
failureDetails.trace = failureDetails.trace?.concat('\n\n', testResult.failureDetails.join('\n'))

Check failure on line 188 in src/generate-report.ts

View workflow job for this annotation

GitHub Actions / build

Replace `'\n\n',·testResult.failureDetails.join('\n')` with `⏎··········'\n\n',⏎··········testResult.failureDetails.join('\n')⏎········`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, failureMessage was assigned to trace. Was this intended?
And is it possible to just join failureDetails which is Array<unknown>. I don't know how to handle this properly

}
return failureDetails
}
Expand Down
26 changes: 25 additions & 1 deletion test/generate-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ describe('GenerateDetailedCtrfReport', () => {
fullName: 'Test Case Full Name',
ancestorTitles: ['parent'],
duration: 100,

failureMessages: [
'Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m"b"\u001b[39m\nReceived: \u001b[31mundefined\u001b[39m\n at Object.<anonymous> (/jest-ctrf-json-reporter/test/generate-report.test.ts:133:41)\n at Promise.then.completed (/jest-ctrf-json-reporter/node_modules/jest-circus/build/utils.js:298:28)\n',
],
Expand All @@ -251,4 +250,29 @@ describe('GenerateDetailedCtrfReport', () => {
'at Object.<anonymous> (/jest-ctrf-json-reporter/test/generate-report.test.ts:133:41)\nat Promise.then.completed (/jest-ctrf-json-reporter/node_modules/jest-circus/build/utils.js:298:28)\n'
)
})

it('should append failureDetails to trace', () => {
const mockTestCaseResult = {
status: 'failed' as Status,
fullName: 'Test Case Full Name',
ancestorTitles: ['parent'],
failureDetails: ['details'],
duration: 100,
failureMessages: [
'Error: \u001b[2mexpect(\u001b[22m\u001b[31mreceived\u001b[39m\u001b[2m).\u001b[22mtoBe\u001b[2m(\u001b[22m\u001b[32mexpected\u001b[39m\u001b[2m) // Object.is equality\u001b[22m\n\nExpected: \u001b[32m"b"\u001b[39m\nReceived: \u001b[31mundefined\u001b[39m\n at Object.<anonymous> (/jest-ctrf-json-reporter/test/generate-report.test.ts:133:41)\n at Promise.then.completed (/jest-ctrf-json-reporter/node_modules/jest-circus/build/utils.js:298:28)\n',
],
}
const mockResult: TestResult = {
testFilePath: '/path/to/test.ts',
testResults: [mockTestCaseResult],
} as TestResult

;(reporter as any).updateCtrfTestResultsFromTestResult(mockResult)

const updatedTestResult = reporter['ctrfReport'].results.tests[0]

expect(updatedTestResult.trace).toBe(
'at Object.<anonymous> (/jest-ctrf-json-reporter/test/generate-report.test.ts:133:41)\nat Promise.then.completed (/jest-ctrf-json-reporter/node_modules/jest-circus/build/utils.js:298:28)\n\n\ndetails'
)
})
})
Loading