From c431590d659e36e18416de0bdfea8d22c9b94cf5 Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Mon, 20 Dec 2021 13:39:24 -0800 Subject: [PATCH] Fixed reporting of suites that are skipped due to a beforeAll failure --- lib/jasmine-core/jasmine.js | 36 +++++++++++--------- spec/core/integration/SpecRunningSpec.js | 42 ++++++++++++++---------- src/core/Env.js | 36 +++++++++++--------- 3 files changed, 66 insertions(+), 48 deletions(-) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index ebd18505..f0f9deeb 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -1972,32 +1972,38 @@ getJasmineRequireObj().Env = function(j$) { reporter.suiteStarted(child.result, resolve); }); await reportChildrenOfBeforeAllFailure(child); - markNotRun(child); + + // Marking the suite passed is consistent with how suites that + // contain failed specs but no suite-level failures are reported. + child.result.status = 'passed'; + await new Promise(function(resolve) { reporter.suiteDone(child.result, resolve); }); - } /* a spec */ else { + } else { + /* a spec */ await new Promise(function(resolve) { reporter.specStarted(child.result, resolve); }); + + child.addExpectationResult( + false, + { + passed: false, + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' + }, + true + ); + child.result.status = 'failed'; + await new Promise(function(resolve) { - markNotRun(child); reporter.specDone(child.result, resolve); }); } } - - function markNotRun(runnable) { - runnable.addExpectationResult( - false, - { - passed: false, - message: 'Not run because a beforeAll function failed' - }, - true - ); - runnable.result.status = 'failed'; - } } }; diff --git a/spec/core/integration/SpecRunningSpec.js b/spec/core/integration/SpecRunningSpec.js index 4606e479..2ce28901 100644 --- a/spec/core/integration/SpecRunningSpec.js +++ b/spec/core/integration/SpecRunningSpec.js @@ -1113,16 +1113,13 @@ describe('spec running', function() { }) ); + // The child suite should be reported as passed, for consistency with + // suites that contain failing specs but no suite-level errors. expect(reporter.suiteDone).toHaveBeenCalledWith( jasmine.objectContaining({ fullName: 'a nested suite', - status: 'failed', - failedExpectations: [ - jasmine.objectContaining({ - passed: false, - message: 'Not run because a beforeAll function failed' - }) - ] + status: 'passed', + failedExpectations: [] }) ); @@ -1138,7 +1135,10 @@ describe('spec running', function() { failedExpectations: [ jasmine.objectContaining({ passed: false, - message: 'Not run because a beforeAll function failed' + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' }) ] }) @@ -1156,7 +1156,10 @@ describe('spec running', function() { failedExpectations: [ jasmine.objectContaining({ passed: false, - message: 'Not run because a beforeAll function failed' + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' }) ] }) @@ -1214,16 +1217,13 @@ describe('spec running', function() { }) ); + // The child suite should be reported as passed, for consistency with + // suites that contain failing specs but no suite-level errors. expect(reporter.suiteDone).toHaveBeenCalledWith( jasmine.objectContaining({ fullName: 'a suite a nested suite', - status: 'failed', - failedExpectations: [ - jasmine.objectContaining({ - passed: false, - message: 'Not run because a beforeAll function failed' - }) - ] + status: 'passed', + failedExpectations: [] }) ); @@ -1239,7 +1239,10 @@ describe('spec running', function() { failedExpectations: [ jasmine.objectContaining({ passed: false, - message: 'Not run because a beforeAll function failed' + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' }) ] }) @@ -1257,7 +1260,10 @@ describe('spec running', function() { failedExpectations: [ jasmine.objectContaining({ passed: false, - message: 'Not run because a beforeAll function failed' + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' }) ] }) diff --git a/src/core/Env.js b/src/core/Env.js index 14610429..677dacce 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -831,32 +831,38 @@ getJasmineRequireObj().Env = function(j$) { reporter.suiteStarted(child.result, resolve); }); await reportChildrenOfBeforeAllFailure(child); - markNotRun(child); + + // Marking the suite passed is consistent with how suites that + // contain failed specs but no suite-level failures are reported. + child.result.status = 'passed'; + await new Promise(function(resolve) { reporter.suiteDone(child.result, resolve); }); - } /* a spec */ else { + } else { + /* a spec */ await new Promise(function(resolve) { reporter.specStarted(child.result, resolve); }); + + child.addExpectationResult( + false, + { + passed: false, + message: + 'Not run because a beforeAll function failed. The ' + + 'beforeAll failure will be reported on the suite that ' + + 'caused it.' + }, + true + ); + child.result.status = 'failed'; + await new Promise(function(resolve) { - markNotRun(child); reporter.specDone(child.result, resolve); }); } } - - function markNotRun(runnable) { - runnable.addExpectationResult( - false, - { - passed: false, - message: 'Not run because a beforeAll function failed' - }, - true - ); - runnable.result.status = 'failed'; - } } };