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]
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user