Allow jasmine-npm to handle its own load errors

[Fixes #153466462]
This commit is contained in:
Steve Gravrock
2017-12-08 08:16:59 -08:00
parent d16aa550cb
commit eb93d38294
3 changed files with 33 additions and 26 deletions
+13 -12
View File
@@ -763,7 +763,7 @@ getJasmineRequireObj().Env = function(j$) {
var throwOnExpectationFailure = false; var throwOnExpectationFailure = false;
var random = true; var random = true;
var seed = null; var seed = null;
var suppressLoadErrors = false; var handlingLoadErrors = true;
var hasFailures = false; var hasFailures = false;
var currentSuite = function() { var currentSuite = function() {
@@ -830,15 +830,13 @@ getJasmineRequireObj().Env = function(j$) {
var globalErrors = new j$.GlobalErrors(); var globalErrors = new j$.GlobalErrors();
globalErrors.install(); globalErrors.install();
globalErrors.pushListener(function(message, filename, lineno) { globalErrors.pushListener(function(message, filename, lineno) {
if (!suppressLoadErrors) { topSuite.result.failedExpectations.push({
topSuite.result.failedExpectations.push({ passed: false,
passed: false, globalErrorType: 'load',
globalErrorType: 'load', message: message,
message: message, filename: filename,
filename: filename, lineno: lineno
lineno: lineno });
});
}
}); });
this.specFilter = function() { this.specFilter = function() {
@@ -984,7 +982,10 @@ getJasmineRequireObj().Env = function(j$) {
}; };
this.suppressLoadErrors = function() { this.suppressLoadErrors = function() {
suppressLoadErrors = true; if (handlingLoadErrors) {
globalErrors.popListener();
}
handlingLoadErrors = false;
}; };
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
@@ -1013,7 +1014,7 @@ getJasmineRequireObj().Env = function(j$) {
}; };
this.execute = function(runnablesToRun) { this.execute = function(runnablesToRun) {
globalErrors.popListener(); this.suppressLoadErrors();
if(!runnablesToRun) { if(!runnablesToRun) {
if (focusedRunnables.length) { if (focusedRunnables.length) {
+7 -2
View File
@@ -2053,18 +2053,23 @@ describe("Env integration", function() {
}); });
describe('If suppressLoadErrors was called', function() { describe('If suppressLoadErrors was called', function() {
it('does not report errors that occur during loading', function(done) { it('does not report or handle errors that occur during loading', function(done) {
var global = { var global = {
setTimeout: function(fn, delay) { setTimeout(fn, delay) }, setTimeout: function(fn, delay) { setTimeout(fn, delay) },
clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }, clearTimeout: function(fn, delay) { clearTimeout(fn, delay) }
}; };
spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global); spyOn(jasmineUnderTest, 'getGlobal').and.returnValue(global);
var globalErrors = new jasmineUnderTest.GlobalErrors(global);
var onerror = jasmine.createSpy('onerror');
globalErrors.pushListener(onerror);
spyOn(jasmineUnderTest, 'GlobalErrors').and.returnValue(globalErrors);
var env = new jasmineUnderTest.Env(), var env = new jasmineUnderTest.Env(),
reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']); reporter = jasmine.createSpyObj('reporter', ['jasmineDone', 'suiteDone', 'specDone']);
reporter.jasmineDone.and.callFake(function(e) { reporter.jasmineDone.and.callFake(function(e) {
expect(e.failedExpectations).toEqual([]); expect(e.failedExpectations).toEqual([]);
expect(onerror).toHaveBeenCalledWith('Uncaught Error: ENOCHEESE');
done(); done();
}); });
+13 -12
View File
@@ -28,7 +28,7 @@ getJasmineRequireObj().Env = function(j$) {
var throwOnExpectationFailure = false; var throwOnExpectationFailure = false;
var random = true; var random = true;
var seed = null; var seed = null;
var suppressLoadErrors = false; var handlingLoadErrors = true;
var hasFailures = false; var hasFailures = false;
var currentSuite = function() { var currentSuite = function() {
@@ -95,15 +95,13 @@ getJasmineRequireObj().Env = function(j$) {
var globalErrors = new j$.GlobalErrors(); var globalErrors = new j$.GlobalErrors();
globalErrors.install(); globalErrors.install();
globalErrors.pushListener(function(message, filename, lineno) { globalErrors.pushListener(function(message, filename, lineno) {
if (!suppressLoadErrors) { topSuite.result.failedExpectations.push({
topSuite.result.failedExpectations.push({ passed: false,
passed: false, globalErrorType: 'load',
globalErrorType: 'load', message: message,
message: message, filename: filename,
filename: filename, lineno: lineno
lineno: lineno });
});
}
}); });
this.specFilter = function() { this.specFilter = function() {
@@ -249,7 +247,10 @@ getJasmineRequireObj().Env = function(j$) {
}; };
this.suppressLoadErrors = function() { this.suppressLoadErrors = function() {
suppressLoadErrors = true; if (handlingLoadErrors) {
globalErrors.popListener();
}
handlingLoadErrors = false;
}; };
var queueRunnerFactory = function(options) { var queueRunnerFactory = function(options) {
@@ -278,7 +279,7 @@ getJasmineRequireObj().Env = function(j$) {
}; };
this.execute = function(runnablesToRun) { this.execute = function(runnablesToRun) {
globalErrors.popListener(); this.suppressLoadErrors();
if(!runnablesToRun) { if(!runnablesToRun) {
if (focusedRunnables.length) { if (focusedRunnables.length) {