Merge branch 'print_global_error_type' of https://github.com/jbunton-atlassian/jasmine into jbunton-atlassian-print_global_error_type

- Merges #1632 from @jbunton-atlassian
This commit is contained in:
Gregg Van Hove
2019-02-11 08:55:16 -08:00
6 changed files with 61 additions and 21 deletions

View File

@@ -2698,12 +2698,16 @@ getJasmineRequireObj().errors = function() {
};
getJasmineRequireObj().ExceptionFormatter = function(j$) {
var ignoredProperties = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber', 'column', 'description', 'jasmineMessage'];
function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) {
var message = '';
if (error.name && error.message) {
if (error.jasmineMessage) {
message += error.jasmineMessage;
} else if (error.name && error.message) {
message += error.name + ': ' + error.message;
} else if (error.message) {
message += error.message;
@@ -2761,12 +2765,11 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return;
}
var ignored = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber', 'column', 'description'];
var result = {};
var empty = true;
for (var prop in error) {
if (j$.util.arrayContains(ignored, prop)) {
if (j$.util.arrayContains(ignoredProperties, prop)) {
continue;
}
result[prop] = error[prop];
@@ -3193,28 +3196,44 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
};
this.originalHandlers = {};
this.installOne_ = function installOne_(errorType) {
this.jasmineHandlers = {};
this.installOne_ = function installOne_(errorType, jasmineMessage) {
function taggedOnError(error) {
error.jasmineMessage = jasmineMessage + ': ' + error;
var handler = handlers[handlers.length - 1];
if (handler) {
handler(error);
} else {
throw error;
}
}
this.originalHandlers[errorType] = global.process.listeners(errorType);
this.jasmineHandlers[errorType] = taggedOnError;
global.process.removeAllListeners(errorType);
global.process.on(errorType, onerror);
global.process.on(errorType, taggedOnError);
this.uninstall = function uninstall() {
var errorTypes = Object.keys(this.originalHandlers);
for (var iType = 0; iType < errorTypes.length; iType++) {
var errorType = errorTypes[iType];
global.process.removeListener(errorType, onerror);
global.process.removeListener(errorType, this.jasmineHandlers[errorType]);
for (var i = 0; i < this.originalHandlers[errorType].length; i++) {
global.process.on(errorType, this.originalHandlers[errorType][i]);
}
delete this.originalHandlers[errorType];
delete this.jasmineHandlers[errorType];
}
};
};
this.install = function install() {
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
this.installOne_('uncaughtException');
this.installOne_('unhandledRejection');
this.installOne_('uncaughtException', 'Uncaught exception');
this.installOne_('unhandledRejection', 'Unhandled promise rejection');
} else {
var originalHandler = global.onerror;
global.onerror = onerror;
@@ -5430,7 +5449,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
cleanup();
if (j$.isError_(err)) {
if (!(err instanceof StopExecutionError)) {
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
self.fail(err);
}
self.errored = errored = true;

View File

@@ -101,6 +101,7 @@ describe("GlobalErrors", function() {
addedListener(new Error('bar'));
expect(handler).toHaveBeenCalledWith(new Error('bar'));
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe('Uncaught exception: Error: bar');
errors.uninstall();
@@ -127,10 +128,11 @@ describe("GlobalErrors", function() {
errors.pushListener(handler);
var addedListener = fakeGlobal.process.on.calls.argsFor(0)[1];
var addedListener = fakeGlobal.process.on.calls.argsFor(1)[1];
addedListener(new Error('bar'));
expect(handler).toHaveBeenCalledWith(new Error('bar'));
expect(handler.calls.argsFor(0)[0].jasmineMessage).toBe('Unhandled promise rejection: Error: bar');
errors.uninstall();

View File

@@ -1942,10 +1942,10 @@ describe("Env integration", function() {
reporter.jasmineDone.and.callFake(function() {
expect(reporter.suiteDone).toHaveFailedExpectationsForRunnable('async suite', [
/^(((Uncaught )?Error: suite( thrown)?)|(suite thrown))$/
/^(((Uncaught )?(exception: )?Error: suite( thrown)?)|(suite thrown))$/
]);
expect(reporter.specDone).toHaveFailedExpectationsForRunnable('suite async spec', [
/^(((Uncaught )?Error: spec( thrown)?)|(spec thrown))$/
/^(((Uncaught )?(exception: )?Error: spec( thrown)?)|(spec thrown))$/
]);
done();
});

View File

@@ -1,11 +1,15 @@
getJasmineRequireObj().ExceptionFormatter = function(j$) {
var ignoredProperties = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber', 'column', 'description', 'jasmineMessage'];
function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) {
var message = '';
if (error.name && error.message) {
if (error.jasmineMessage) {
message += error.jasmineMessage;
} else if (error.name && error.message) {
message += error.name + ': ' + error.message;
} else if (error.message) {
message += error.message;
@@ -63,12 +67,11 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return;
}
var ignored = ['name', 'message', 'stack', 'fileName', 'sourceURL', 'line', 'lineNumber', 'column', 'description'];
var result = {};
var empty = true;
for (var prop in error) {
if (j$.util.arrayContains(ignored, prop)) {
if (j$.util.arrayContains(ignoredProperties, prop)) {
continue;
}
result[prop] = error[prop];

View File

@@ -14,28 +14,44 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
};
this.originalHandlers = {};
this.installOne_ = function installOne_(errorType) {
this.jasmineHandlers = {};
this.installOne_ = function installOne_(errorType, jasmineMessage) {
function taggedOnError(error) {
error.jasmineMessage = jasmineMessage + ': ' + error;
var handler = handlers[handlers.length - 1];
if (handler) {
handler(error);
} else {
throw error;
}
}
this.originalHandlers[errorType] = global.process.listeners(errorType);
this.jasmineHandlers[errorType] = taggedOnError;
global.process.removeAllListeners(errorType);
global.process.on(errorType, onerror);
global.process.on(errorType, taggedOnError);
this.uninstall = function uninstall() {
var errorTypes = Object.keys(this.originalHandlers);
for (var iType = 0; iType < errorTypes.length; iType++) {
var errorType = errorTypes[iType];
global.process.removeListener(errorType, onerror);
global.process.removeListener(errorType, this.jasmineHandlers[errorType]);
for (var i = 0; i < this.originalHandlers[errorType].length; i++) {
global.process.on(errorType, this.originalHandlers[errorType][i]);
}
delete this.originalHandlers[errorType];
delete this.jasmineHandlers[errorType];
}
};
};
this.install = function install() {
if (global.process && global.process.listeners && j$.isFunction_(global.process.on)) {
this.installOne_('uncaughtException');
this.installOne_('unhandledRejection');
this.installOne_('uncaughtException', 'Uncaught exception');
this.installOne_('unhandledRejection', 'Unhandled promise rejection');
} else {
var originalHandler = global.onerror;
global.onerror = onerror;

View File

@@ -78,7 +78,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
cleanup();
if (j$.isError_(err)) {
if (!(err instanceof StopExecutionError)) {
if (!(err instanceof StopExecutionError) && !err.jasmineMessage) {
self.fail(err);
}
self.errored = errored = true;