From bed1c15ea40194bdf993ba3c45b173006fad90b9 Mon Sep 17 00:00:00 2001 From: Christopher Amavisca and Greg Cobb Date: Thu, 6 Mar 2014 15:39:04 -0800 Subject: [PATCH] HtmlReporter shows error alerts for afterAllExceptions -Add list of exceptions in HtmlReporter to push to on error -Create alerts for each exception in the list (with stack trace) [#67055688] --- lib/jasmine-core/jasmine-html.js | 11 +++++++++-- lib/jasmine-core/jasmine.css | 1 + spec/html/HtmlReporterSpec.js | 29 +++++++++++++++++++---------- src/html/HtmlReporter.js | 11 +++++++++-- src/html/_HTMLReporter.scss | 6 +++++- 5 files changed, 43 insertions(+), 15 deletions(-) diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 724b6b97..65e27823 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -46,7 +46,8 @@ jasmineRequire.HtmlReporter = function(j$) { failureCount = 0, pendingSpecCount = 0, htmlReporterMain, - symbols; + symbols, + exceptionsList = []; this.initialize = function() { htmlReporterMain = createDom('div', {className: 'html-reporter'}, @@ -94,7 +95,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.afterAllException = function(error) { - console.error(error); + exceptionsList.push(error); }; var failures = []; @@ -169,6 +170,12 @@ jasmineRequire.HtmlReporter = function(j$) { var statusBarClassName = 'bar ' + ((failureCount > 0) ? 'failed' : 'passed'); alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage)); + exceptionsList.forEach(function(error) { + var errorBarMessage = 'An error was thrown in an afterAll: ' + error.stack; + var errorBarClassName = 'bar errored'; + alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage)); + }); + var results = find('.results'); results.appendChild(summary); diff --git a/lib/jasmine-core/jasmine.css b/lib/jasmine-core/jasmine.css index c622f643..e91f5fa3 100644 --- a/lib/jasmine-core/jasmine.css +++ b/lib/jasmine-core/jasmine.css @@ -25,6 +25,7 @@ body { background-color: #eeeeee; padding: 0; margin: 5px; overflow-y: scroll; } .html-reporter .bar.failed { background-color: #ca3a11; } .html-reporter .bar.passed { background-color: #007069; } .html-reporter .bar.skipped { background-color: #bababa; } +.html-reporter .bar.errored { background-color: #ca3a11; } .html-reporter .bar.menu { background-color: #fff; color: #aaaaaa; } .html-reporter .bar.menu a { color: #333333; } .html-reporter .bar a { color: white; } diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index 25b4ae71..20eb24d9 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -130,24 +130,33 @@ describe("New HtmlReporter", function() { }); }); - describe("when afterAllException is called", function () { - it("sends a console error", function(){ + describe("when there are afterAllExceptions", function () { + it("displays the exceptions in their own alert bars", function(){ var env = new j$.Env(), - error = new Error('After all exception!'), - container = document.createElement('div'), - getContainer = function () { return container; }, + container = document.createElement("div"), + getContainer = function() { return container; }, reporter = new j$.HtmlReporter({ env: env, + getContainer: getContainer, createElement: function() { return document.createElement.apply(document, arguments); }, - createTextNode: function() { return document.createTextNode.apply(document, arguments); }, - getContainer: getContainer - }); + createTextNode: function() { return document.createTextNode.apply(document, arguments); } + }), + error = new Error('My After All Exception'), + otherError = new Error('My Other Exception'); reporter.initialize(); - spyOn(window.console, 'error'); + reporter.jasmineStarted({}); reporter.afterAllException(error); - expect(window.console.error).toHaveBeenCalled(); + reporter.afterAllException(otherError); + reporter.jasmineDone({}); + + var alertBars = container.querySelectorAll(".alert .bar"); + + expect(alertBars.length).toEqual(3); + expect(alertBars[1].innerHTML).toMatch(/My After All Exception/); + expect(alertBars[1].getAttribute("class")).toEqual('bar errored'); + expect(alertBars[2].innerHTML).toMatch(/My Other Exception/); }); }); diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index e03b8948..f4a121a5 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -17,7 +17,8 @@ jasmineRequire.HtmlReporter = function(j$) { failureCount = 0, pendingSpecCount = 0, htmlReporterMain, - symbols; + symbols, + exceptionsList = []; this.initialize = function() { htmlReporterMain = createDom('div', {className: 'html-reporter'}, @@ -65,7 +66,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.afterAllException = function(error) { - console.error(error); + exceptionsList.push(error); }; var failures = []; @@ -140,6 +141,12 @@ jasmineRequire.HtmlReporter = function(j$) { var statusBarClassName = 'bar ' + ((failureCount > 0) ? 'failed' : 'passed'); alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage)); + exceptionsList.forEach(function(error) { + var errorBarMessage = 'An error was thrown in an afterAll: ' + error.stack; + var errorBarClassName = 'bar errored'; + alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage)); + }); + var results = find('.results'); results.appendChild(summary); diff --git a/src/html/_HTMLReporter.scss b/src/html/_HTMLReporter.scss index 7b1c76ab..3abfc44a 100644 --- a/src/html/_HTMLReporter.scss +++ b/src/html/_HTMLReporter.scss @@ -152,7 +152,7 @@ body { color: #eee; &.failed { - background-color: $failing-color + background-color: $failing-color; } &.passed { @@ -163,6 +163,10 @@ body { background-color: $neutral-color; } + &.errored { + background-color: $failing-color; + } + &.menu { background-color: #fff; color: $faint-text-color;