After all exceptions dispatch to reporter hook
- Add 'afterAllException' hook to reporter dispatch, we might want to make this more generic in the future - Add afterAllException function to HtmlReporter [#66789174]
This commit is contained in:
@@ -93,6 +93,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
currentParent.addChild(result, 'spec');
|
currentParent.addChild(result, 'spec');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.afterAllException = function(error) {
|
||||||
|
console.error(error);
|
||||||
|
};
|
||||||
|
|
||||||
var failures = [];
|
var failures = [];
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
if (result.status != 'disabled') {
|
if (result.status != 'disabled') {
|
||||||
|
|||||||
@@ -408,7 +408,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
'suiteStarted',
|
'suiteStarted',
|
||||||
'suiteDone',
|
'suiteDone',
|
||||||
'specStarted',
|
'specStarted',
|
||||||
'specDone'
|
'specDone',
|
||||||
|
'afterAllException'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.specFilter = function() {
|
this.specFilter = function() {
|
||||||
@@ -539,6 +540,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var queueRunnerFactory = function(options) {
|
var queueRunnerFactory = function(options) {
|
||||||
options.catchException = catchException;
|
options.catchException = catchException;
|
||||||
|
options.reporter = reporter;
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||||
|
|
||||||
@@ -721,7 +723,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.afterAll = function(afterAllFunction) {
|
this.afterAll = function(afterAllFunction) {
|
||||||
currentDeclarationSuite.afterAll({ fn: afterAllFunction, timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.afterAll({ fn: afterAllFunction, isAfterAll: true, timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pending = function() {
|
this.pending = function() {
|
||||||
@@ -1581,6 +1583,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
this.catchException = attrs.catchException || function() { return true; };
|
this.catchException = attrs.catchException || function() { return true; };
|
||||||
this.userContext = attrs.userContext || {};
|
this.userContext = attrs.userContext || {};
|
||||||
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||||
|
this.reporter = attrs.reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueRunner.prototype.execute = function() {
|
QueueRunner.prototype.execute = function() {
|
||||||
@@ -1588,7 +1591,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
|
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
|
||||||
var length = queueableFns.length,
|
var runner = this,
|
||||||
|
length = queueableFns.length,
|
||||||
self = this,
|
self = this,
|
||||||
iterativeIndex;
|
iterativeIndex;
|
||||||
|
|
||||||
@@ -1611,6 +1615,9 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
try {
|
try {
|
||||||
queueableFn.fn.call(self.userContext);
|
queueableFn.fn.call(self.userContext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if(queueableFn.isAfterAll){
|
||||||
|
runner.reporter.afterAllException(e);
|
||||||
|
}
|
||||||
handleException(e);
|
handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1635,6 +1642,9 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
try {
|
try {
|
||||||
queueableFn.fn.call(self.userContext, next);
|
queueableFn.fn.call(self.userContext, next);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if(queueableFn.isAfterAll) {
|
||||||
|
runner.reporter.afterAllException(e);
|
||||||
|
}
|
||||||
handleException(e);
|
handleException(e);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ describe("Env integration", function() {
|
|||||||
expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
|
expect(reporter.specDone.calls.argsFor(1)[0].failedExpectations[0].message)
|
||||||
.toEqual("Expected 1 to be 2.");
|
.toEqual("Expected 1 to be 2.");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
env.addReporter(reporter);
|
env.addReporter(reporter);
|
||||||
|
|
||||||
@@ -328,6 +328,58 @@ describe("Env integration", function() {
|
|||||||
env.execute();
|
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','afterAllException']);
|
||||||
|
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(function() {
|
||||||
|
expect(reporter.afterAllException).toHaveBeenCalledWith(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
|
||||||
|
env.describe('my suite', function() {
|
||||||
|
env.it('my spec', function() {
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(function() {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
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','afterAllException']);
|
||||||
|
|
||||||
|
|
||||||
|
reporter.jasmineDone.and.callFake(function() {
|
||||||
|
expect(reporter.afterAllException).toHaveBeenCalledWith(error);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
env.addReporter(reporter);
|
||||||
|
|
||||||
|
env.describe('my suite', function() {
|
||||||
|
env.it('my spec', function() {
|
||||||
|
});
|
||||||
|
|
||||||
|
env.afterAll(function(done) {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
env.execute();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it("Allows specifying which specs and suites to run", function(done) {
|
it("Allows specifying which specs and suites to run", function(done) {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
calls = [],
|
calls = [],
|
||||||
|
|||||||
@@ -130,6 +130,27 @@ describe("New HtmlReporter", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when afterAllException is called", function () {
|
||||||
|
it("sends a console error", function(){
|
||||||
|
var env = new j$.Env(),
|
||||||
|
error = new Error('After all exception!'),
|
||||||
|
container = document.createElement('div'),
|
||||||
|
getContainer = function () { return container; },
|
||||||
|
reporter = new j$.HtmlReporter({
|
||||||
|
env: env,
|
||||||
|
createElement: function() { return document.createElement.apply(document, arguments); },
|
||||||
|
createTextNode: function() { return document.createTextNode.apply(document, arguments); },
|
||||||
|
getContainer: getContainer
|
||||||
|
});
|
||||||
|
|
||||||
|
reporter.initialize();
|
||||||
|
|
||||||
|
spyOn(window.console, 'error');
|
||||||
|
reporter.afterAllException(error);
|
||||||
|
expect(window.console.error).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("when Jasmine is done", function() {
|
describe("when Jasmine is done", function() {
|
||||||
it("reports the run time", function() {
|
it("reports the run time", function() {
|
||||||
var env = new j$.Env(),
|
var env = new j$.Env(),
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
'suiteStarted',
|
'suiteStarted',
|
||||||
'suiteDone',
|
'suiteDone',
|
||||||
'specStarted',
|
'specStarted',
|
||||||
'specDone'
|
'specDone',
|
||||||
|
'afterAllException'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.specFilter = function() {
|
this.specFilter = function() {
|
||||||
@@ -165,6 +166,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
|
|
||||||
var queueRunnerFactory = function(options) {
|
var queueRunnerFactory = function(options) {
|
||||||
options.catchException = catchException;
|
options.catchException = catchException;
|
||||||
|
options.reporter = reporter;
|
||||||
options.clearStack = options.clearStack || clearStack;
|
options.clearStack = options.clearStack || clearStack;
|
||||||
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
|
||||||
|
|
||||||
@@ -347,7 +349,7 @@ getJasmineRequireObj().Env = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.afterAll = function(afterAllFunction) {
|
this.afterAll = function(afterAllFunction) {
|
||||||
currentDeclarationSuite.afterAll({ fn: afterAllFunction, timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
currentDeclarationSuite.afterAll({ fn: afterAllFunction, isAfterAll: true, timeout: function() { return j$.DEFAULT_TIMEOUT_INTERVAL; } });
|
||||||
};
|
};
|
||||||
|
|
||||||
this.pending = function() {
|
this.pending = function() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
this.catchException = attrs.catchException || function() { return true; };
|
this.catchException = attrs.catchException || function() { return true; };
|
||||||
this.userContext = attrs.userContext || {};
|
this.userContext = attrs.userContext || {};
|
||||||
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
|
||||||
|
this.reporter = attrs.reporter;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueRunner.prototype.execute = function() {
|
QueueRunner.prototype.execute = function() {
|
||||||
@@ -25,7 +26,8 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
|
QueueRunner.prototype.run = function(queueableFns, recursiveIndex) {
|
||||||
var length = queueableFns.length,
|
var runner = this,
|
||||||
|
length = queueableFns.length,
|
||||||
self = this,
|
self = this,
|
||||||
iterativeIndex;
|
iterativeIndex;
|
||||||
|
|
||||||
@@ -48,6 +50,9 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
try {
|
try {
|
||||||
queueableFn.fn.call(self.userContext);
|
queueableFn.fn.call(self.userContext);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if(queueableFn.isAfterAll){
|
||||||
|
runner.reporter.afterAllException(e);
|
||||||
|
}
|
||||||
handleException(e);
|
handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,6 +77,9 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
|||||||
try {
|
try {
|
||||||
queueableFn.fn.call(self.userContext, next);
|
queueableFn.fn.call(self.userContext, next);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if(queueableFn.isAfterAll) {
|
||||||
|
runner.reporter.afterAllException(e);
|
||||||
|
}
|
||||||
handleException(e);
|
handleException(e);
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ jasmineRequire.HtmlReporter = function(j$) {
|
|||||||
currentParent.addChild(result, 'spec');
|
currentParent.addChild(result, 'spec');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.afterAllException = function(error) {
|
||||||
|
console.error(error);
|
||||||
|
};
|
||||||
|
|
||||||
var failures = [];
|
var failures = [];
|
||||||
this.specDone = function(result) {
|
this.specDone = function(result) {
|
||||||
if (result.status != 'disabled') {
|
if (result.status != 'disabled') {
|
||||||
|
|||||||
Reference in New Issue
Block a user