From 668846147cecaba6c88812631e7357ac8f369776 Mon Sep 17 00:00:00 2001 From: Christopher Amavisca and Greg Cobb Date: Thu, 6 Mar 2014 18:25:49 -0800 Subject: [PATCH] Fix issues with displaying error messages for afterAll (browser compatibility) - Switch from showing error stack to showing message/description since only chrome/ff support stack - Fallback to error.description if error.message is undefined - Made exceptionList variable name consistent between both reporters --- lib/console/console.js | 6 +++--- lib/jasmine-core/jasmine-html.js | 10 +++++----- spec/console/ConsoleReporterSpec.js | 2 +- src/console/ConsoleReporter.js | 6 +++--- src/html/HtmlReporter.js | 10 +++++----- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/console/console.js b/lib/console/console.js index 772fc5f4..eccd6062 100644 --- a/lib/console/console.js +++ b/lib/console/console.js @@ -87,13 +87,13 @@ getJasmineRequireObj().ConsoleReporter = function() { print('Finished in ' + seconds + ' ' + plural('second', seconds)); printNewline(); - exceptionList.forEach(function(error) { + for(i = 0; i < exceptionList.length; i++) { printNewline(); print(colored('red', 'An error was thrown in an afterAll')); printNewline(); - print(colored('red', error.stack)); + print(colored('red', (exceptionList[i].message || exceptionList[i].description))); printNewline(); - }); + } onComplete(failureCount === 0); }; diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 65e27823..b372e3bb 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -47,7 +47,7 @@ jasmineRequire.HtmlReporter = function(j$) { pendingSpecCount = 0, htmlReporterMain, symbols, - exceptionsList = []; + exceptionList = []; this.initialize = function() { htmlReporterMain = createDom('div', {className: 'html-reporter'}, @@ -95,7 +95,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.afterAllException = function(error) { - exceptionsList.push(error); + exceptionList.push(error); }; var failures = []; @@ -170,11 +170,11 @@ 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; + for(i = 0; i < exceptionList.length; i++) { + var errorBarMessage = 'An error was thrown in an afterAll: ' + (exceptionList[i].message || exceptionList[i].description); var errorBarClassName = 'bar errored'; alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage)); - }); + } var results = find('.results'); results.appendChild(summary); diff --git a/spec/console/ConsoleReporterSpec.js b/spec/console/ConsoleReporterSpec.js index 5e158d1f..86204fd2 100644 --- a/spec/console/ConsoleReporterSpec.js +++ b/spec/console/ConsoleReporterSpec.js @@ -232,7 +232,7 @@ describe("ConsoleReporter", function() { reporter.afterAllException(error); reporter.afterAllException(anotherError); reporter.jasmineDone(); - + expect(out.getOutput()).toMatch(/After All Exception/); expect(out.getOutput()).toMatch(/Some Other Exception/); }); diff --git a/src/console/ConsoleReporter.js b/src/console/ConsoleReporter.js index cdd11b0f..bfd15273 100644 --- a/src/console/ConsoleReporter.js +++ b/src/console/ConsoleReporter.js @@ -52,13 +52,13 @@ getJasmineRequireObj().ConsoleReporter = function() { print('Finished in ' + seconds + ' ' + plural('second', seconds)); printNewline(); - exceptionList.forEach(function(error) { + for(i = 0; i < exceptionList.length; i++) { printNewline(); print(colored('red', 'An error was thrown in an afterAll')); printNewline(); - print(colored('red', error.stack)); + print(colored('red', (exceptionList[i].message || exceptionList[i].description))); printNewline(); - }); + } onComplete(failureCount === 0); }; diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index f4a121a5..effa58bd 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -18,7 +18,7 @@ jasmineRequire.HtmlReporter = function(j$) { pendingSpecCount = 0, htmlReporterMain, symbols, - exceptionsList = []; + exceptionList = []; this.initialize = function() { htmlReporterMain = createDom('div', {className: 'html-reporter'}, @@ -66,7 +66,7 @@ jasmineRequire.HtmlReporter = function(j$) { }; this.afterAllException = function(error) { - exceptionsList.push(error); + exceptionList.push(error); }; var failures = []; @@ -141,11 +141,11 @@ 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; + for(i = 0; i < exceptionList.length; i++) { + var errorBarMessage = 'An error was thrown in an afterAll: ' + (exceptionList[i].message || exceptionList[i].description); var errorBarClassName = 'bar errored'; alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessage)); - }); + } var results = find('.results'); results.appendChild(summary);