Suites report errors in afterAlls in the suiteDone event

- remove `afterAllEvent` from reporters
This commit is contained in:
slackersoft
2014-09-03 18:52:13 -07:00
parent 6b857d11ce
commit 9402d59859
14 changed files with 306 additions and 203 deletions

View File

@@ -187,9 +187,9 @@ describe("ConsoleReporter", function() {
expect(onComplete).toHaveBeenCalledWith(false);
});
it('calls it with false if there are afterAll events', function() {
reporter.afterAllEvent("bananas");
it('calls it with false if there are suite failures', function() {
reporter.specDone({status: "passed"});
reporter.suiteDone({failedExpectations: [{ message: 'bananas' }] });
reporter.jasmineDone();
expect(onComplete).toHaveBeenCalledWith(false);
});
@@ -244,12 +244,10 @@ describe("ConsoleReporter", function() {
var reporter = new j$.ConsoleReporter({
print: out.print,
showColors: true
}),
error = new Error('After All Exception'),
anotherError = new Error('Some Other Exception');
});
reporter.afterAllEvent(error);
reporter.afterAllEvent(anotherError);
reporter.suiteDone({ failedExpectations: [{ message: 'After All Exception' }] });
reporter.suiteDone({ failedExpectations: [{ message: 'Some Other Exception' }] });
reporter.jasmineDone();
expect(out.getOutput()).toMatch(/After All Exception/);

View File

@@ -98,12 +98,10 @@ describe("QueueRunner", function() {
beforeFn = { fn: function(done) { }, type: 'before', timeout: function() { return timeout; } },
queueableFn = { fn: jasmine.createSpy('fn'), type: 'queueable' },
onComplete = jasmine.createSpy('onComplete'),
reportException = jasmine.createSpy('reportException'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
reportException: reportException,
onException: onException
});
@@ -112,7 +110,6 @@ describe("QueueRunner", function() {
jasmine.clock().tick(timeout);
expect(reportException).toHaveBeenCalledWith(jasmine.any(Error), 'before');
expect(onException).toHaveBeenCalledWith(jasmine.any(Error));
expect(queueableFn.fn).toHaveBeenCalled();
expect(onComplete).toHaveBeenCalled();
@@ -122,12 +119,10 @@ describe("QueueRunner", function() {
var beforeFn = { fn: function(done) { } },
queueableFn = { fn: jasmine.createSpy('fn') },
onComplete = jasmine.createSpy('onComplete'),
reportException = jasmine.createSpy('reportException'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueableFns: [beforeFn, queueableFn],
onComplete: onComplete,
reportException: reportException,
onException: onException,
});
@@ -136,7 +131,6 @@ describe("QueueRunner", function() {
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(reportException).not.toHaveBeenCalled();
expect(onException).not.toHaveBeenCalled();
expect(queueableFn.fn).not.toHaveBeenCalled();
expect(onComplete).not.toHaveBeenCalled();
@@ -145,35 +139,29 @@ describe("QueueRunner", function() {
it("clears the timeout when an async function throws an exception, to prevent additional exception reporting", function() {
var queueableFn = { fn: function(done) { throw new Error("error!"); } },
onComplete = jasmine.createSpy('onComplete'),
reportException = jasmine.createSpy('reportException'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
reportException: reportException,
onException: onException
});
queueRunner.execute();
expect(onComplete).toHaveBeenCalled();
expect(reportException).toHaveBeenCalled();
expect(onException).toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(reportException.calls.count()).toEqual(1);
expect(onException.calls.count()).toEqual(1);
});
it("clears the timeout when the done callback is called", function() {
var queueableFn = { fn: function(done) { done(); } },
onComplete = jasmine.createSpy('onComplete'),
reportException = jasmine.createSpy('reportException'),
onException = jasmine.createSpy('onException'),
queueRunner = new j$.QueueRunner({
queueableFns: [queueableFn],
onComplete: onComplete,
reportException: reportException,
onException: onException
});
@@ -182,7 +170,6 @@ describe("QueueRunner", function() {
expect(onComplete).toHaveBeenCalled();
jasmine.clock().tick(j$.DEFAULT_TIMEOUT_INTERVAL);
expect(reportException).not.toHaveBeenCalled();
expect(onException).not.toHaveBeenCalled();
});
@@ -218,17 +205,14 @@ describe("QueueRunner", function() {
fn: function() {
throw new Error('fake error');
} },
exceptionCallback = jasmine.createSpy('exception callback'),
onExceptionCallback = jasmine.createSpy('on exception callback'),
queueRunner = new j$.QueueRunner({
queueableFns: [queueableFn],
reportException: exceptionCallback,
onException: onExceptionCallback
});
queueRunner.execute();
expect(exceptionCallback).toHaveBeenCalledWith(jasmine.any(Error), 'queueable');
expect(onExceptionCallback).toHaveBeenCalledWith(jasmine.any(Error));
});

View File

@@ -262,7 +262,8 @@ describe("Suite", function() {
id: suite.id,
status: '',
description: "with a child suite",
fullName: "with a child suite"
fullName: "with a child suite",
failedExpectations: []
});
});
});

View File

@@ -330,11 +330,29 @@ describe("Env integration", function() {
it("reports when an afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent).toHaveBeenCalledWith('Expectation failed: Expected 1 to equal 2.');
expect(reporter.afterAllEvent).toHaveBeenCalledWith('Expectation failed: Expected 2 to equal 3.');
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
failedExpectations: [
{
matcherName : 'toEqual',
expected : 2,
actual : 1,
message : 'Expected 1 to equal 2.',
stack: jasmine.any(String),
passed: false
},
{
matcherName : 'toEqual',
expected : 3,
actual : 2,
message : 'Expected 2 to equal 3.',
stack: jasmine.any(String),
passed: false
}
]
}));
done();
});
@@ -353,46 +371,23 @@ describe("Env integration", function() {
env.execute();
});
it("only reports afterAll expectation failures once, regardless of suite children", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent.calls.count()).toEqual(1);
expect(reporter.afterAllEvent).toHaveBeenCalledWith('Expectation failed: Expected 1 to equal 2.');
done();
});
env.addReporter(reporter);
env.describe('my suite', function() {
env.it('my spec', function() {
});
env.it('my spec2', function() {
});
env.describe('nested suite', function(){
env.it('my spec3', function() {
});
});
env.afterAll(function() {
env.expect(1).toEqual(2);
});
});
env.execute();
});
it("reports when afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent.calls.count()).toEqual(1);
expect(reporter.afterAllEvent).toHaveBeenCalledWith('Error thrown: After All Exception');
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'my suite',
failedExpectations: [{
matcherName : '',
expected : '',
actual : '',
message : 'Error: After All Exception',
stack : jasmine.any(String),
passed: false
}]
}));
done();
});
@@ -412,10 +407,19 @@ describe("Env integration", function() {
it("reports when an async afterAll fails an expectation", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent).toHaveBeenCalledWith('Expectation failed: Expected 1 to equal 2.');
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
failedExpectations: [{
matcherName : 'toEqual',
expected : 2,
actual : 1,
message : 'Expected 1 to equal 2.',
stack: jasmine.any(String),
passed: false
}]
}));
done();
});
@@ -437,11 +441,21 @@ describe("Env integration", function() {
it("reports when an async afterAll throws an exception", function(done) {
var env = new j$.Env(),
error = new Error('After All Exception'),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent).toHaveBeenCalled();
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
description: 'my suite',
failedExpectations: [{
matcherName : '',
expected : '',
actual : '',
message : 'Error: After All Exception',
stack : jasmine.any(String),
passed: false
}]
}));
done();
});
@@ -747,10 +761,19 @@ describe("Env integration", function() {
it("should wait the specified interval before reporting an afterAll that fails to call done", function(done) {
var env = new j$.Env(),
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','afterAllEvent']);
reporter = jasmine.createSpyObj('fakeReport', ['jasmineDone','suiteDone']);
reporter.jasmineDone.and.callFake(function() {
expect(reporter.afterAllEvent).toHaveBeenCalledWith(jasmine.any(String));
expect(reporter.suiteDone).toHaveBeenCalledWith(jasmine.objectContaining({
failedExpectations: [{
matcherName : '',
expected : '',
actual : '',
message : 'Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.',
stack : jasmine.any(String),
passed: false
}]
}));
done();
});

View File

@@ -130,7 +130,7 @@ describe("New HtmlReporter", function() {
});
});
describe("when there are afterAllEvents", function () {
describe("when there are suite failures", function () {
it("displays the exceptions in their own alert bars", function(){
var env = new j$.Env(),
container = document.createElement("div"),
@@ -140,15 +140,13 @@ describe("New HtmlReporter", function() {
getContainer: getContainer,
createElement: function() { return document.createElement.apply(document, arguments); },
createTextNode: function() { return document.createTextNode.apply(document, arguments); }
}),
error = new Error('My After All Exception'),
otherError = new Error('My Other Exception');
});
reporter.initialize();
reporter.jasmineStarted({});
reporter.afterAllEvent(error);
reporter.afterAllEvent(otherError);
reporter.suiteDone({ failedExpectations: [{ message: 'My After All Exception' }] });
reporter.suiteDone({ failedExpectations: [{ message: 'My Other Exception' }] });
reporter.jasmineDone({});
var alertBars = container.querySelectorAll(".alert .bar");