Files
jasmine/src/core/ExceptionFormatter.js
2017-11-13 15:49:01 -08:00

58 lines
1.5 KiB
JavaScript

getJasmineRequireObj().ExceptionFormatter = function(j$) {
function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) {
var message = '';
if (error.name && error.message) {
message += error.name + ': ' + error.message;
} else {
message += error.toString() + ' thrown';
}
if (error.fileName || error.sourceURL) {
message += ' in ' + (error.fileName || error.sourceURL);
}
if (error.line || error.lineNumber) {
message += ' (line ' + (error.line || error.lineNumber) + ')';
}
return message;
};
this.stack = function(error) {
if (!error || !error.stack) {
return null;
}
var stackTrace = new j$.StackTrace(error.stack);
var lines = filterJasmine(stackTrace);
if (stackTrace.message) {
lines.unshift(stackTrace.message);
}
return lines.join('\n');
};
function filterJasmine(stackTrace) {
var result = [],
jasmineMarker = stackTrace.style === 'webkit' ? '<Jasmine>' : ' at <Jasmine>';
stackTrace.frames.forEach(function(frame) {
if (frame.file && frame.file !== jasmineFile) {
result.push(frame.raw);
} else if (result[result.length - 1] !== jasmineMarker) {
result.push(jasmineMarker);
}
});
return result;
}
}
return ExceptionFormatter;
};