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 all commits
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
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'
)
})
})
Loading