From 9b1d05d5253e9ebc04ede59826576dca28ce4fbc Mon Sep 17 00:00:00 2001 From: Ryan Manuel Date: Mon, 14 Nov 2022 14:52:19 -0600 Subject: [PATCH] fix: junit reporters crashing on failed asserts (#24677) * fix: junit reporters crashing on failures * handle other platforms * Fix system tests * fix snapshot * fix snapshot * fix snapshot --- system-tests/__snapshots__/reporters_spec.js | 45 +++++++++++++++++-- system-tests/test/reporters_spec.js | 18 +++++--- .../prod-darwin/snapshot-meta.cache.json | 8 ++-- .../cache/prod-linux/snapshot-meta.cache.json | 8 ++-- .../cache/prod-win32/snapshot-meta.cache.json | 8 ++-- .../v8-snapshot/src/setup/force-no-rewrite.ts | 4 ++ 6 files changed, 70 insertions(+), 21 deletions(-) diff --git a/system-tests/__snapshots__/reporters_spec.js b/system-tests/__snapshots__/reporters_spec.js index e296872898..dbb8308724 100644 --- a/system-tests/__snapshots__/reporters_spec.js +++ b/system-tests/__snapshots__/reporters_spec.js @@ -9,6 +9,8 @@ We searched for the reporter in these paths: Learn more at https://on.cypress.io/reporters Error: Cannot find module '/foo/bar/.projects/e2e/node_modules/module-does-not-exist' +Require stack: +- lib/reporter.js [stack trace lines] ` @@ -21,14 +23,14 @@ exports['e2e reporters supports junit reporter and reporter options 1'] = ` ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │ Cypress: 1.2.3 │ │ Browser: FooBrowser 88 │ - │ Specs: 1 found (simple_passing.cy.js) │ - │ Searched: cypress/e2e/simple_passing.cy.js │ + │ Specs: 2 found (simple_passing.cy.js, simple_failing.cy.js) │ + │ Searched: cypress/e2e/simple_passing.cy.js, cypress/e2e/simple_failing.cy.js │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ ──────────────────────────────────────────────────────────────────────────────────────────────────── - Running: simple_passing.cy.js (1 of 1) + Running: simple_passing.cy.js (1 of 2) (Results) @@ -51,6 +53,39 @@ exports['e2e reporters supports junit reporter and reporter options 1'] = ` - Finished processing: /XXX/XXX/XXX/cypress/videos/simple_passing.cy.js.mp4 (X second) +──────────────────────────────────────────────────────────────────────────────────────────────────── + + Running: simple_failing.cy.js (2 of 2) + + (Results) + + ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ + │ Tests: 2 │ + │ Passing: 0 │ + │ Failing: 2 │ + │ Pending: 0 │ + │ Skipped: 0 │ + │ Screenshots: 2 │ + │ Video: true │ + │ Duration: X seconds │ + │ Spec Ran: simple_failing.cy.js │ + └────────────────────────────────────────────────────────────────────────────────────────────────┘ + + + (Screenshots) + + - /XXX/XXX/XXX/cypress/screenshots/simple_failing.cy.js/simple failing spec -- fai (1280x720) + ls1 (failed).png + - /XXX/XXX/XXX/cypress/screenshots/simple_failing.cy.js/simple failing spec -- fai (1280x720) + ls2 (failed).png + + + (Video) + + - Started processing: Compressing to 32 CRF + - Finished processing: /XXX/XXX/XXX/cypress/videos/simple_failing.cy.js.mp4 (X second) + + ==================================================================================================== (Run Finished) @@ -59,8 +94,10 @@ exports['e2e reporters supports junit reporter and reporter options 1'] = ` Spec Tests Passing Failing Pending Skipped ┌────────────────────────────────────────────────────────────────────────────────────────────────┐ │ ✔ simple_passing.cy.js XX:XX 1 1 - - - │ + ├────────────────────────────────────────────────────────────────────────────────────────────────┤ + │ ✖ simple_failing.cy.js XX:XX 2 - 2 - - │ └────────────────────────────────────────────────────────────────────────────────────────────────┘ - ✔ All specs passed! XX:XX 1 1 - - - + ✖ 1 of 2 failed (50%) XX:XX 3 1 2 - - ` diff --git a/system-tests/test/reporters_spec.js b/system-tests/test/reporters_spec.js index 5add439b90..4941778b19 100644 --- a/system-tests/test/reporters_spec.js +++ b/system-tests/test/reporters_spec.js @@ -36,22 +36,30 @@ describe('e2e reporters', () => { it('supports junit reporter and reporter options', function () { return systemTests.exec(this, { - spec: 'simple_passing.cy.js', + spec: 'simple_passing.cy.js,simple_failing.cy.js', snapshot: true, reporter: 'junit', reporterOptions: 'mochaFile=junit-output/result.[hash].xml,testCaseSwitchClassnameAndName=true', + expectedExitCode: 2, }) .then(() => { return glob(path.join(e2ePath, 'junit-output', 'result.*.xml')) .then((paths) => { - expect(paths.length).to.eq(1) + expect(paths.length).to.eq(2) + + return Promise.all([fs.readFileAsync(paths[0], 'utf8'), fs.readFileAsync(paths[1], 'utf8')]) + .then((results) => { + const str = results.join('') - return fs.readFileAsync(paths[0], 'utf8') - .then((str) => { expect(str).to.include('