Removed duplicate message from errors (incl. matcher failures) on V8

This commit is contained in:
Steve Gravrock
2021-11-16 12:52:07 -08:00
parent 2a049015b0
commit 7a685b16f6
6 changed files with 79 additions and 11 deletions

View File

@@ -3843,7 +3843,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return message;
};
this.stack = function(error) {
this.stack = function(error, { omitMessage } = {}) {
if (!error || !error.stack) {
return null;
}
@@ -3852,7 +3852,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
var lines = filterJasmine(stackTrace);
var result = '';
if (stackTrace.message) {
if (stackTrace.message && !omitMessage) {
lines.unshift(stackTrace.message);
}
@@ -4302,7 +4302,9 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
}
}
}
return stackFormatter(error);
// Omit the message from the stack trace because it will be
// included elsewhere.
return stackFormatter(error, { omitMessage: true });
}
}

View File

@@ -225,5 +225,61 @@ describe('ExceptionFormatter', function() {
expect(result).toMatch(/error properties:.*someProperty.*hello there/);
});
describe('When omitMessage is true', function() {
it('filters the message from V8-style stack traces', function() {
const error = {
message: 'nope',
stack:
'Error: nope\n' +
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
' at fn2 (http://localhost:8888/__jasmine__/jasmine.js:4320:20)\n' +
' at fn3 (http://localhost:8888/__jasmine__/jasmine.js:4320:20)\n' +
' at fn4 (http://localhost:8888/__spec__/core/UtilSpec.js:110:19)\n'
};
const subject = new jasmineUnderTest.ExceptionFormatter({
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
});
const result = subject.stack(error, { omitMessage: true });
expect(result).toEqual(
' at fn1 (http://localhost:8888/__spec__/core/UtilSpec.js:115:19)\n' +
' at <Jasmine>\n' +
' at fn4 (http://localhost:8888/__spec__/core/UtilSpec.js:110:19)'
);
});
it('handles Webkit style traces that do not include a message', function() {
const error = {
stack:
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
'fn1@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
'fn2@http://localhost:8888/__jasmine__/jasmine.js:4320:27\n' +
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
};
const subject = new jasmineUnderTest.ExceptionFormatter({
jasmineFile: 'http://localhost:8888/__jasmine__/jasmine.js'
});
const result = subject.stack(error, { omitMessage: true });
expect(result).toEqual(
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28\n' +
'<Jasmine>\n' +
'http://localhost:8888/__spec__/core/UtilSpec.js:115:28'
);
});
it('ensures that stack traces do not include the message in this environment', function() {
let error;
try {
throw new Error('an error');
} catch (e) {
error = e;
}
const subject = new jasmineUnderTest.ExceptionFormatter({
jasmineFile: jasmine.util.jasmineFile()
});
const result = subject.stack(error, { omitMessage: true });
expect(result).not.toContain('an error');
});
});
});
});

View File

@@ -50,7 +50,9 @@ describe('buildExpectationResult', function() {
stackFormatter: stackFormatter
});
expect(stackFormatter).toHaveBeenCalledWith(fakeError);
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
omitMessage: true
});
expect(result.stack).toEqual('foo');
});
@@ -66,7 +68,9 @@ describe('buildExpectationResult', function() {
stackFormatter: stackFormatter
});
expect(stackFormatter).toHaveBeenCalledWith(fakeError);
expect(stackFormatter).toHaveBeenCalledWith(fakeError, {
omitMessage: true
});
expect(result.stack).toEqual('foo');
});

View File

@@ -2839,7 +2839,7 @@ describe('Env integration', function() {
expect(result.deprecationWarnings).toEqual([
jasmine.objectContaining({
message: topLevelError.message,
stack: exceptionFormatter.stack(topLevelError)
stack: exceptionFormatter.stack(topLevelError, { omitMessage: true })
})
]);
@@ -2849,7 +2849,9 @@ describe('Env integration', function() {
deprecationWarnings: [
jasmine.objectContaining({
message: suiteLevelError.message,
stack: exceptionFormatter.stack(suiteLevelError)
stack: exceptionFormatter.stack(suiteLevelError, {
omitMessage: true
})
})
]
})
@@ -2861,7 +2863,9 @@ describe('Env integration', function() {
deprecationWarnings: [
jasmine.objectContaining({
message: specLevelError.message,
stack: exceptionFormatter.stack(specLevelError)
stack: exceptionFormatter.stack(specLevelError, {
omitMessage: true
})
})
]
})

View File

@@ -38,7 +38,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
return message;
};
this.stack = function(error) {
this.stack = function(error, { omitMessage } = {}) {
if (!error || !error.stack) {
return null;
}
@@ -47,7 +47,7 @@ getJasmineRequireObj().ExceptionFormatter = function(j$) {
var lines = filterJasmine(stackTrace);
var result = '';
if (stackTrace.message) {
if (stackTrace.message && !omitMessage) {
lines.unshift(stackTrace.message);
}

View File

@@ -76,7 +76,9 @@ getJasmineRequireObj().buildExpectationResult = function(j$) {
}
}
}
return stackFormatter(error);
// Omit the message from the stack trace because it will be
// included elsewhere.
return stackFormatter(error, { omitMessage: true });
}
}