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

Separate the Stack and The Error from a TestCase Failure #224

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions __tests__/buildJsonResults.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,16 @@ describe('buildJsonResults', () => {
noStackTrace: "true"
}));

const failureMsg = jsonResults.testsuites[1].testsuite[2].testcase[1].failure;
const failureInstance = jsonResults.testsuites[1].testsuite[2].testcase[1].failure

const failureMsg = failureInstance[0]._attr.message;
const failureStack = failureInstance[1]

// Make sure no escape codes are there that exist in the mock
expect(failureMsg.includes('\u001b')).toBe(false);
expect(failureStack).toBe(undefined);
expect(failureMsg).toMatch('Should fail');
expect(failureMsg).not.toMatch('at _callee$ (path/to/failing.test.js:26:15)');
expect(failureMsg).not.toMatch('at path/to/failing.test.js:2:554');

});

it('should parse messages with stack trace when notStackTrace set to false and jest >= 26.3.0', () => {
Expand All @@ -328,10 +330,10 @@ describe('buildJsonResults', () => {
const failureMsg = jsonResults.testsuites[1].testsuite[2].testcase[1].failure;

// Make sure no escape codes are there that exist in the mock
expect(failureMsg.includes('\u001b')).toBe(false);
expect(failureMsg).toMatch('Should fail');
expect(failureMsg).toMatch('at _callee$ (path/to/failing.test.js:26:15)');
expect(failureMsg).toMatch('at path/to/failing.test.js:2:554');
expect(failureMsg[1].includes('\u001b')).toBe(false);
expect(failureMsg[0]._attr.message).toMatch('Should fail');
expect(failureMsg[1]).toMatch('at _callee$ (path/to/failing.test.js:26:15)');
expect(failureMsg[1]).toMatch('at path/to/failing.test.js:2:554');

});

Expand Down
9 changes: 6 additions & 3 deletions utils/buildJsonResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,16 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file
// Write out all failure messages as <failure> tags
// Nested underneath <testcase> tag
if (tc.status === testFailureStatus || tc.status === testErrorStatus) {
const failureMessages = junitOptions.noStackTrace === 'true' && tc.failureDetails ?
tc.failureDetails.map(detail => detail.message) : tc.failureMessages;

const failureMessages = tc.failureDetails ? tc.failureDetails.map(detail => ({
message: detail.message,
stack: junitOptions.noStackTrace === "true" ? undefined : detail.stack,
})) : tc.failureMessages;

failureMessages.forEach((failure) => {
const tagName = tc.status === testFailureStatus ? 'failure': testErrorStatus
testCase.testcase.push({
[tagName]: stripAnsi(failure)
[tagName]: typeof failure === "string" ? stripAnsi(failure): [{ _attr: {message: stripAnsi(failure.message)} }, stripAnsi(failure.stack)]
});
})
}
Expand Down