Skip to content

Commit

Permalink
fix(console): Re-add Error: to the stack (#228)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
johnjbarton committed Nov 14, 2018
1 parent 6663e47 commit d0b980d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/adapter.js
Expand Up @@ -70,6 +70,7 @@ function formatFailedStep (step) {
// Remove the message prior to processing the stack to prevent issues like
// https://github.com/karma-runner/karma-jasmine/issues/79
var stack = step.stack.replace('Error: ' + step.message, '')
var prefix = (stack === step.stack) ? '' : 'Error: '

var dirtyRelevantStack = getRelevantStackFrom(stack)

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

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

// Now we probably have a repetition case where:
// relevantMessage: ["Expected true to be false."]
Expand Down
4 changes: 2 additions & 2 deletions test/adapter.spec.js
Expand Up @@ -204,7 +204,7 @@ describe('jasmine adapter', function () {

karma.result.and.callFake(function (result) {
expect(result.log).toEqual([
'Expected true to be false.\n' +
'Error: Expected true to be false.\n' +
' at /foo/bar/baz.spec.js:23:29\n' +
' at /foo/bar/baz.js:18:20'
])
Expand All @@ -230,7 +230,7 @@ describe('jasmine adapter', function () {

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

0 comments on commit d0b980d

Please sign in to comment.