Skip to content

Commit 295cc23

Browse files
committed
fix(console): Re-add Error: to the stack
Chrome devtools looks for a pattern in stack traces and if it finds a match it will shorten and linkify the stack, and apply sourcemaps. The pattern fails when the "Error: " is removed. So we put it back for debugging's sake.
1 parent fce80bf commit 295cc23

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/adapter.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function formatFailedStep (step) {
7070
// Remove the message prior to processing the stack to prevent issues like
7171
// https://github.com/karma-runner/karma-jasmine/issues/79
7272
var stack = step.stack.replace('Error: ' + step.message, '')
73+
var prefix = (stack === step.stack) ? '' : 'Error: '
7374

7475
var dirtyRelevantStack = getRelevantStackFrom(stack)
7576

@@ -85,14 +86,14 @@ function formatFailedStep (step) {
8586
} else {
8687
// Stack entry is already in the message,
8788
// we consider it to be a suitable message alternative:
88-
relevantMessage.push(dirtyRelevantStack[i])
89+
relevantMessage.push(prefix + dirtyRelevantStack[i])
8990
}
9091
}
9192

9293
// In most cases the above will leave us with an empty message...
9394
if (relevantMessage.length === 0) {
9495
// Let's reuse the original message:
95-
relevantMessage.push(step.message)
96+
relevantMessage.push(prefix + step.message)
9697

9798
// Now we probably have a repetition case where:
9899
// relevantMessage: ["Expected true to be false."]

test/adapter.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ describe('jasmine adapter', function () {
203203

204204
karma.result.and.callFake(function (result) {
205205
expect(result.log).toEqual([
206-
'Expected true to be false.\n' +
206+
'Error: Expected true to be false.\n' +
207207
' at /foo/bar/baz.spec.js:23:29\n' +
208208
' at /foo/bar/baz.js:18:20'
209209
])
@@ -229,7 +229,7 @@ describe('jasmine adapter', function () {
229229

230230
karma.result.and.callFake(function (result) {
231231
expect(result.log).toEqual([
232-
'Expected true to be false.\n' +
232+
'Error: Expected true to be false.\n' +
233233
' at stack (/foo/bar/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1441:17)\n' +
234234
' at buildExpectationResult (/foo/bar/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1411:14)\n' +
235235
' at Spec.Env.expectationResultFactory (/foo/bar/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:533:18)\n' +

0 commit comments

Comments
 (0)