Fail if error events (e.g. syntax errors) occur during loading
[#24901981]
This commit is contained in:
committed by
Steve Gravrock
parent
12ed3bfacd
commit
bd250f27c7
@@ -709,6 +709,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var throwOnExpectationFailure = false;
|
||||
var random = true;
|
||||
var seed = null;
|
||||
var suppressLoadErrors = false;
|
||||
|
||||
var currentSuite = function() {
|
||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||
@@ -772,6 +773,15 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
]);
|
||||
|
||||
var globalErrors = new j$.GlobalErrors();
|
||||
globalErrors.install();
|
||||
globalErrors.pushListener(function(message) {
|
||||
if (!suppressLoadErrors) {
|
||||
topSuite.result.failedExpectations.push({
|
||||
passed: false,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
@@ -915,6 +925,10 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return seed;
|
||||
};
|
||||
|
||||
this.suppressLoadErrors = function() {
|
||||
suppressLoadErrors = true;
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchException = catchException;
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
@@ -941,6 +955,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.execute = function(runnablesToRun) {
|
||||
globalErrors.popListener();
|
||||
|
||||
if(!runnablesToRun) {
|
||||
if (focusedRunnables.length) {
|
||||
runnablesToRun = focusedRunnables;
|
||||
@@ -996,11 +1012,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
currentlyExecutingSuites.push(topSuite);
|
||||
|
||||
globalErrors.install();
|
||||
processor.execute(function() {
|
||||
clearResourcesForRunnable(topSuite.id);
|
||||
currentlyExecutingSuites.pop();
|
||||
globalErrors.uninstall();
|
||||
|
||||
/**
|
||||
* Information passed to the {@link Reporter#jasmineDone} event.
|
||||
@@ -2398,8 +2412,6 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
this.uninstall = function noop() {};
|
||||
|
||||
this.install = function install() {
|
||||
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
|
||||
var originalHandlers = global.process.listeners('uncaughtException');
|
||||
|
||||
@@ -1974,4 +1974,64 @@ describe("Env integration", function() {
|
||||
|
||||
env.execute();
|
||||
});
|
||||
|
||||
describe("In a browser", function() {
|
||||
if (typeof document !== 'undefined') {
|
||||
it('reports errors that occur during loading', function(done) {
|
||||
var global = {
|
||||
setTimeout: function(fn, delay) { setTimeout(fn, delay) },
|
||||
clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
|
||||
};
|
||||
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
|
||||
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function(e) {
|
||||
expect(e.failedExpectations).toEqual([
|
||||
{
|
||||
passed: false,
|
||||
message: 'Uncaught SyntaxError: Unexpected end of input'
|
||||
},
|
||||
{
|
||||
passed: false,
|
||||
message: 'Uncaught Error: ENOCHEESE'
|
||||
}
|
||||
]);
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
global.onerror('Uncaught SyntaxError: Unexpected end of input');
|
||||
global.onerror('Uncaught Error: ENOCHEESE');
|
||||
|
||||
env.execute();
|
||||
});
|
||||
}
|
||||
|
||||
describe('If suppressLoadErrors was called', function() {
|
||||
it('does not report errors that occur during loading', function(done) {
|
||||
var global = {
|
||||
setTimeout: function(fn, delay) { setTimeout(fn, delay) },
|
||||
clearTimeout: function(fn, delay) { clearTimeout(fn, delay) },
|
||||
};
|
||||
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
|
||||
|
||||
var env = new jasmineUnderTest.Env(),
|
||||
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
|
||||
|
||||
reporter.jasmineDone.and.callFake(function(e) {
|
||||
expect(e.failedExpectations).toEqual([]);
|
||||
done();
|
||||
});
|
||||
|
||||
env.addReporter(reporter);
|
||||
env.suppressLoadErrors(true);
|
||||
global.onerror('Uncaught Error: ENOCHEESE');
|
||||
|
||||
env.execute();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var throwOnExpectationFailure = false;
|
||||
var random = true;
|
||||
var seed = null;
|
||||
var suppressLoadErrors = false;
|
||||
|
||||
var currentSuite = function() {
|
||||
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
|
||||
@@ -91,6 +92,15 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
]);
|
||||
|
||||
var globalErrors = new j$.GlobalErrors();
|
||||
globalErrors.install();
|
||||
globalErrors.pushListener(function(message) {
|
||||
if (!suppressLoadErrors) {
|
||||
topSuite.result.failedExpectations.push({
|
||||
passed: false,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
@@ -234,6 +244,10 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
return seed;
|
||||
};
|
||||
|
||||
this.suppressLoadErrors = function() {
|
||||
suppressLoadErrors = true;
|
||||
};
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchException = catchException;
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
@@ -260,6 +274,8 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
this.execute = function(runnablesToRun) {
|
||||
globalErrors.popListener();
|
||||
|
||||
if(!runnablesToRun) {
|
||||
if (focusedRunnables.length) {
|
||||
runnablesToRun = focusedRunnables;
|
||||
@@ -315,11 +331,9 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
currentlyExecutingSuites.push(topSuite);
|
||||
|
||||
globalErrors.install();
|
||||
processor.execute(function() {
|
||||
clearResourcesForRunnable(topSuite.id);
|
||||
currentlyExecutingSuites.pop();
|
||||
globalErrors.uninstall();
|
||||
|
||||
/**
|
||||
* Information passed to the {@link Reporter#jasmineDone} event.
|
||||
|
||||
@@ -13,8 +13,6 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
||||
}
|
||||
};
|
||||
|
||||
this.uninstall = function noop() {};
|
||||
|
||||
this.install = function install() {
|
||||
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
|
||||
var originalHandlers = global.process.listeners('uncaughtException');
|
||||
|
||||
Reference in New Issue
Block a user