Report loading errors as loading errors, not afterAll errors

[#24901981]
This commit is contained in:
Steve Gravrock
2017-11-01 13:42:15 -07:00
parent 7b8edcb401
commit 26a7bc6acf
7 changed files with 79 additions and 11 deletions

View File

@@ -242,18 +242,19 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage, seedBar));
var errorBarClassName = 'jasmine-bar jasmine-errored';
var errorBarMessagePrefix = 'AfterAll ';
var afterAllMessagePrefix = 'AfterAll ';
for(var i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failedSuite.failedExpectations[j].message));
alert.appendChild(createDom('span', {className: errorBarClassName}, afterAllMessagePrefix + failedSuite.failedExpectations[j].message));
}
}
for(i = 0; i < globalFailures.length; i++) {
var failure = globalFailures[i];
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
var prefix = failure.globalErrorType === 'load' ? 'Error during loading: ' : afterAllMessagePrefix;
alert.appendChild(createDom('span', {className: errorBarClassName}, prefix + failure.message));
}
var results = find('.jasmine-results');

View File

@@ -778,6 +778,7 @@ getJasmineRequireObj().Env = function(j$) {
if (!suppressLoadErrors) {
topSuite.result.failedExpectations.push({
passed: false,
globalErrorType: 'load',
message: message
});
}
@@ -5177,7 +5178,13 @@ getJasmineRequireObj().Suite = function(j$) {
actual: '',
error: arguments[0]
};
this.result.failedExpectations.push(this.expectationResultFactory(data));
var failedExpectation = this.expectationResultFactory(data);
if (!this.parentSuite) {
failedExpectation.globalErrorType = 'afterAll';
}
this.result.failedExpectations.push(failedExpectation);
} else {
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];

View File

@@ -422,6 +422,49 @@ describe("Env integration", function() {
env.execute();
});
it("tags top-level afterAll failures with a type", function(done) {
var env = new jasmineUnderTest.Env();
env.addReporter({jasmineDone: function(result) {
expect(result.failedExpectations[0].globalErrorType).toEqual('afterAll');
done();
}});
env.it('has a spec', function() {});
env.afterAll(function() {
debugger;
throw 'nope';
});
env.execute();
});
it("does not tag suite afterAll failures with a type", function(done) {
var env = new jasmineUnderTest.Env(),
reporter = {
jasmineDone: function() {
expect(reporter.suiteDone).toHaveBeenCalled();
done();
},
suiteDone: jasmine.createSpy('suiteDone').and.callFake(function(result) {
expect(result.failedExpectations[0].globalErrorType).toBeFalsy();
})
}
env.addReporter(reporter);
env.describe('a suite', function() {
env.it('has a spec', function() {});
env.afterAll(function() {
throw 'nope';
});
});
env.execute();
});
it("fails all underlying specs when the beforeAll fails", function (done) {
var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('fakeReporter', [ "specDone", "jasmineDone" ]);
@@ -1991,10 +2034,12 @@ describe("Env integration", function() {
expect(e.failedExpectations).toEqual([
{
passed: false,
globalErrorType: 'load',
message: 'Uncaught SyntaxError: Unexpected end of input'
},
{
passed: false,
globalErrorType: 'load',
message: 'Uncaught Error: ENOCHEESE'
}
]);

View File

@@ -195,16 +195,23 @@ describe("HtmlReporter", function() {
reporter.jasmineStarted({});
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My After All Exception' }] });
reporter.suiteDone({ status: 'failed', failedExpectations: [{ message: 'My Other Exception' }] });
reporter.jasmineDone({ failedExpectations: [{ message: 'Global After All Failure' }, { message: 'Other Global' }] });
reporter.jasmineDone({ failedExpectations: [
{ message: 'Global After All Failure', globalErrorType: 'afterAll' },
{ message: 'Other Global' },
{ message: 'Your JS is borken', globalErrorType: 'load' }
] });
var alertBars = container.querySelectorAll(".jasmine-alert .jasmine-bar");
expect(alertBars.length).toEqual(5);
expect(alertBars.length).toEqual(6);
expect(alertBars[1].innerHTML).toMatch(/My After All Exception/);
expect(alertBars[1].getAttribute("class")).toEqual('jasmine-bar jasmine-errored');
expect(alertBars[2].innerHTML).toMatch(/My Other Exception/);
expect(alertBars[3].innerHTML).toMatch(/Global After All Failure/);
expect(alertBars[3].innerHTML).toMatch(/AfterAll Global After All Failure/);
// TODO: What about this?
expect(alertBars[4].innerHTML).toMatch(/Other Global/);
expect(alertBars[5].innerHTML).toMatch(/Error during loading: Your JS is borken/);
});
});

View File

@@ -97,6 +97,7 @@ getJasmineRequireObj().Env = function(j$) {
if (!suppressLoadErrors) {
topSuite.result.failedExpectations.push({
passed: false,
globalErrorType: 'load',
message: message
});
}

View File

@@ -119,7 +119,13 @@ getJasmineRequireObj().Suite = function(j$) {
actual: '',
error: arguments[0]
};
this.result.failedExpectations.push(this.expectationResultFactory(data));
var failedExpectation = this.expectationResultFactory(data);
if (!this.parentSuite) {
failedExpectation.globalErrorType = 'afterAll';
}
this.result.failedExpectations.push(failedExpectation);
} else {
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];

View File

@@ -213,18 +213,19 @@ jasmineRequire.HtmlReporter = function(j$) {
alert.appendChild(createDom('span', {className: statusBarClassName}, statusBarMessage, seedBar));
var errorBarClassName = 'jasmine-bar jasmine-errored';
var errorBarMessagePrefix = 'AfterAll ';
var afterAllMessagePrefix = 'AfterAll ';
for(var i = 0; i < failedSuites.length; i++) {
var failedSuite = failedSuites[i];
for(var j = 0; j < failedSuite.failedExpectations.length; j++) {
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failedSuite.failedExpectations[j].message));
alert.appendChild(createDom('span', {className: errorBarClassName}, afterAllMessagePrefix + failedSuite.failedExpectations[j].message));
}
}
for(i = 0; i < globalFailures.length; i++) {
var failure = globalFailures[i];
alert.appendChild(createDom('span', {className: errorBarClassName}, errorBarMessagePrefix + failure.message));
var prefix = failure.globalErrorType === 'load' ? 'Error during loading: ' : afterAllMessagePrefix;
alert.appendChild(createDom('span', {className: errorBarClassName}, prefix + failure.message));
}
var results = find('.jasmine-results');