Skip to content

Commit

Permalink
Merge pull request #13 from an-ky/fix/handle-failureDetails
Browse files Browse the repository at this point in the history
fix: handling of AssertionResult.failureDetails
  • Loading branch information
Ma11hewThomas authored Jun 11, 2024
2 parents 616b2b8 + f807542 commit aec0f8c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/generate-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class GenerateCtrfReport implements Reporter {
failureDetails.message = joinedMessages
.slice(0, match?.index)
.replace(colorCodesPattern, '')

failureDetails.trace = joinedMessages
.slice(match?.index)
.split('\n')
Expand All @@ -184,7 +185,10 @@ class GenerateCtrfReport implements Reporter {
}

if (testResult.failureDetails !== undefined) {
failureDetails.trace = testResult.failureMessages.join('\r\n')
failureDetails.trace = failureDetails.trace?.concat(
'\n\n',
testResult.failureDetails.join('\n')
)
}
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'
)
})
})

0 comments on commit aec0f8c

Please sign in to comment.