Fixed de-duplication of exception messages containing blank lines on Node and Chrome
This is particularly helpful when reporting testing-library errors, which have messages that contain blank lines and can be hundreds or even thousands of lines long.
This commit is contained in:
@@ -9889,9 +9889,7 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
|
||||
getJasmineRequireObj().StackTrace = function(j$) {
|
||||
function StackTrace(error) {
|
||||
let lines = error.stack.split('\n').filter(function(line) {
|
||||
return line !== '';
|
||||
});
|
||||
let lines = error.stack.split('\n');
|
||||
|
||||
const extractResult = extractMessage(error.message, lines);
|
||||
|
||||
@@ -9900,6 +9898,10 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
||||
lines = extractResult.remainder;
|
||||
}
|
||||
|
||||
lines = lines.filter(function(line) {
|
||||
return line !== '';
|
||||
});
|
||||
|
||||
const parseResult = tryParseFrames(lines);
|
||||
this.frames = parseResult.frames;
|
||||
this.style = parseResult.style;
|
||||
|
||||
@@ -51,6 +51,27 @@ describe('StackTrace', function() {
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Chrome/Edge style traces with messages containing blank lines', function() {
|
||||
const error = {
|
||||
message: 'line 1\n\nline 2',
|
||||
stack:
|
||||
'Error: line 1\n\nline 2\n' +
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
};
|
||||
|
||||
const result = new jasmineUnderTest.StackTrace(error);
|
||||
|
||||
expect(result.message).toEqual('Error: line 1\n\nline 2');
|
||||
const rawFrames = result.frames.map(function(f) {
|
||||
return f.raw;
|
||||
});
|
||||
expect(rawFrames).toEqual([
|
||||
' at UserContext.<anonymous> (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)',
|
||||
' at QueueRunner.run (http://localhost:8888/__jasmine__/jasmine.js:4320:20)'
|
||||
]);
|
||||
});
|
||||
|
||||
it('understands Node style traces', function() {
|
||||
const error = {
|
||||
message: 'nope',
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
getJasmineRequireObj().StackTrace = function(j$) {
|
||||
function StackTrace(error) {
|
||||
let lines = error.stack.split('\n').filter(function(line) {
|
||||
return line !== '';
|
||||
});
|
||||
let lines = error.stack.split('\n');
|
||||
|
||||
const extractResult = extractMessage(error.message, lines);
|
||||
|
||||
@@ -11,6 +9,10 @@ getJasmineRequireObj().StackTrace = function(j$) {
|
||||
lines = extractResult.remainder;
|
||||
}
|
||||
|
||||
lines = lines.filter(function(line) {
|
||||
return line !== '';
|
||||
});
|
||||
|
||||
const parseResult = tryParseFrames(lines);
|
||||
this.frames = parseResult.frames;
|
||||
this.style = parseResult.style;
|
||||
|
||||
Reference in New Issue
Block a user