From abaf7e86dd27c86ce84dbeb6d8176fd51471b550 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 23 Sep 2022 15:23:46 -0700 Subject: [PATCH 1/3] asdfdsf --- __tests__/buildJsonResults.test.js | 15 +++++++++------ utils/buildJsonResults.js | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/__tests__/buildJsonResults.test.js b/__tests__/buildJsonResults.test.js index ed0de19..27c5b89 100644 --- a/__tests__/buildJsonResults.test.js +++ b/__tests__/buildJsonResults.test.js @@ -308,10 +308,13 @@ 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.includes('\u001b')).toBe(false); 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'); @@ -328,10 +331,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[0]._attr.message).toMatch('Should fail'); + expect(failureMsg[1].includes('\u001b')).toBe(false); + 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'); }); diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index 1b41a7c..519dad4 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -68,13 +68,16 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file // Write out all failure messages as tags // Nested underneath 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" ? "" : 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: failure.message} }, stripAnsi(failure.stack)] }); }) } From a5936b4cf3cbf541b82d7f0333b4ef787e94c99f Mon Sep 17 00:00:00 2001 From: marcin Date: Mon, 26 Sep 2022 10:39:42 -0700 Subject: [PATCH 2/3] updated. --- __tests__/buildJsonResults.test.js | 3 +-- utils/buildJsonResults.js | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/__tests__/buildJsonResults.test.js b/__tests__/buildJsonResults.test.js index 27c5b89..b221623 100644 --- a/__tests__/buildJsonResults.test.js +++ b/__tests__/buildJsonResults.test.js @@ -314,11 +314,10 @@ describe('buildJsonResults', () => { const failureStack = failureInstance[1] // Make sure no escape codes are there that exist in the mock - expect(failureStack.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', () => { diff --git a/utils/buildJsonResults.js b/utils/buildJsonResults.js index 519dad4..0133e96 100644 --- a/utils/buildJsonResults.js +++ b/utils/buildJsonResults.js @@ -71,13 +71,13 @@ const generateTestCase = function(junitOptions, suiteOptions, tc, filepath, file const failureMessages = tc.failureDetails ? tc.failureDetails.map(detail => ({ message: detail.message, - stack: junitOptions.noStackTrace === "true" ? "" : detail.stack, + stack: junitOptions.noStackTrace === "true" ? undefined : detail.stack, })) : tc.failureMessages; failureMessages.forEach((failure) => { const tagName = tc.status === testFailureStatus ? 'failure': testErrorStatus testCase.testcase.push({ - [tagName]: typeof failure === "string" ? stripAnsi(failure): [{ _attr: {message: failure.message} }, stripAnsi(failure.stack)] + [tagName]: typeof failure === "string" ? stripAnsi(failure): [{ _attr: {message: stripAnsi(failure.message)} }, stripAnsi(failure.stack)] }); }) } From 719b85dbc74e9441c11a509fac4c71d483d78640 Mon Sep 17 00:00:00 2001 From: marcin Date: Mon, 26 Sep 2022 14:22:02 -0700 Subject: [PATCH 3/3] easier to read changes. --- __tests__/buildJsonResults.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/buildJsonResults.test.js b/__tests__/buildJsonResults.test.js index b221623..524f69c 100644 --- a/__tests__/buildJsonResults.test.js +++ b/__tests__/buildJsonResults.test.js @@ -330,8 +330,8 @@ 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[0]._attr.message).toMatch('Should fail'); 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');