Filter Jasmine frames from stack traces

[Finishes #2644992]
This commit is contained in:
Steve Gravrock
2017-11-08 22:44:29 -08:00
parent 59ad217954
commit 5906a2c05c
8 changed files with 557 additions and 10 deletions

View File

@@ -1,5 +1,7 @@
getJasmineRequireObj().ExceptionFormatter = function() {
function ExceptionFormatter() {
getJasmineRequireObj().ExceptionFormatter = function(j$) {
function ExceptionFormatter(options) {
var jasmineFile = (options && options.jasmineFile) || j$.util.jasmineFile();
this.message = function(error) {
var message = '';
@@ -21,8 +23,34 @@ getJasmineRequireObj().ExceptionFormatter = function() {
};
this.stack = function(error) {
return error ? error.stack : null;
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;