From 7b8edcb401ff113ed32287ac5c55be04f87508ef Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Wed, 1 Nov 2017 11:44:58 -0700 Subject: [PATCH] HTML reporter reports overall failure if there are any global errors [#24901981] --- lib/jasmine-core/jasmine-html.js | 9 +++--- spec/html/HtmlReporterSpec.js | 52 ++++++++++++++++++++++++++++++++ src/html/HtmlReporter.js | 9 +++--- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index a33e6c17..97b83b2f 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -218,12 +218,14 @@ jasmineRequire.HtmlReporter = function(j$) { ); } var statusBarMessage = ''; - var statusBarClassName = 'jasmine-bar '; + var statusBarClassName = 'jasmine-overall-result jasmine-bar '; + var globalFailures = (doneResult && doneResult.failedExpectations) || []; + var failed = failureCount + globalFailures.length > 0; - if (totalSpecsDefined > 0) { + if (totalSpecsDefined > 0 || failed) { statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } - statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed'; + statusBarClassName += failed ? 'jasmine-failed' : 'jasmine-passed'; } else { statusBarClassName += 'jasmine-skipped'; statusBarMessage += 'No specs found'; @@ -249,7 +251,6 @@ jasmineRequire.HtmlReporter = function(j$) { } } - var globalFailures = (doneResult && doneResult.failedExpectations) || []; for(i = 0; i < globalFailures.length; i++) { var failure = globalFailures[i]; alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message)); diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index e84bbd0a..10f04fa5 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -733,6 +733,58 @@ describe("HtmlReporter", function() { expect(alertBars[0].innerHTML).toMatch(/No specs found/); }); + it("reports failure if there are global errors and no specs", function() { + var env = new jasmineUnderTest.Env(), + container = document.createElement("div"), + reporter = new jasmineUnderTest.HtmlReporter({ + env: env, + getContainer: function() { return container; }, + createElement: function() { return document.createElement.apply(document, arguments); }, + createTextNode: function() { return document.createTextNode.apply(document, arguments); } + }); + reporter.initialize(); + reporter.jasmineStarted({ totalSpecsDefined: 0 }); + reporter.jasmineDone({ + failedExpectations: [{ + passed: false, + message: 'nope' + }] + }); + + var alertBar = container.querySelector(".jasmine-overall-result"); + expect(alertBar.getAttribute('class')).toMatch(/jasmine-failed/); + }); + + it("reports failure if there are global errors and some specs", function() { + var env = new jasmineUnderTest.Env(), + container = document.createElement("div"), + reporter = new jasmineUnderTest.HtmlReporter({ + env: env, + getContainer: function() { return container; }, + createElement: function() { return document.createElement.apply(document, arguments); }, + createTextNode: function() { return document.createTextNode.apply(document, arguments); } + }); + reporter.initialize(); + reporter.jasmineStarted({ totalSpecsDefined: 0 }); + reporter.specDone({ + id: 123, + description: "with a spec", + fullName: "A Suite with a spec", + status: "passed", + passedExpectations: [{passed: true}], + failedExpectations: [] + }); + reporter.jasmineDone({ + failedExpectations: [{ + passed: false, + message: 'nope' + }] + }); + + var alertBar = container.querySelector(".jasmine-overall-result"); + expect(alertBar.getAttribute('class')).toMatch(/jasmine-failed/); + }); + describe("and all specs pass", function() { var env, container, reporter; beforeEach(function() { diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 02a9e1ce..8ae8998c 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -189,12 +189,14 @@ jasmineRequire.HtmlReporter = function(j$) { ); } var statusBarMessage = ''; - var statusBarClassName = 'jasmine-bar '; + var statusBarClassName = 'jasmine-overall-result jasmine-bar '; + var globalFailures = (doneResult && doneResult.failedExpectations) || []; + var failed = failureCount + globalFailures.length > 0; - if (totalSpecsDefined > 0) { + if (totalSpecsDefined > 0 || failed) { statusBarMessage += pluralize('spec', specsExecuted) + ', ' + pluralize('failure', failureCount); if (pendingSpecCount) { statusBarMessage += ', ' + pluralize('pending spec', pendingSpecCount); } - statusBarClassName += (failureCount > 0) ? 'jasmine-failed' : 'jasmine-passed'; + statusBarClassName += failed ? 'jasmine-failed' : 'jasmine-passed'; } else { statusBarClassName += 'jasmine-skipped'; statusBarMessage += 'No specs found'; @@ -220,7 +222,6 @@ jasmineRequire.HtmlReporter = function(j$) { } } - var globalFailures = (doneResult && doneResult.failedExpectations) || []; for(i = 0; i < globalFailures.length; i++) { var failure = globalFailures[i]; alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));