Skip to content

Commit

Permalink
fix(stack): On error in beforeAll/afterAll relevant information to de…
Browse files Browse the repository at this point in the history
…bug are miss… (#232)

* On error in beforeAll/afterAll relevant information to debug are missing.

e.g. on Firefix no stack is available so construct one if filename and
lineno are available.

* fix eslint error: Extra semicolon  semi
  • Loading branch information
mschaaf authored and johnjbarton committed Mar 25, 2019
1 parent 097eed4 commit cd6f060
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,24 @@ function getRelevantStackFrom (stack) {
* @return {String} Formatted step.
*/
function formatFailedStep (step) {
// Safari seems to have no stack trace,
// so we just return the error message:
if (!step.stack) { return step.message }

var relevantMessage = []
var relevantStack = []

// Safari/Firefox seems to have no stack trace,
// so we just return the error message and if available
// construct a stacktrace out of filename and lineno:
if (!step.stack) {
if (step.filename) {
let stackframe = step.filename
if (step.lineno) {
stackframe = stackframe + ':' + step.lineno
}
relevantStack.push(stackframe)
}
relevantMessage.push(step.message)
return relevantMessage.concat(relevantStack).join('\n')
}

// 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, '')
Expand Down
10 changes: 10 additions & 0 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,16 @@ describe('jasmine adapter', function () {
expect(formatFailedStep(step)).toBe('MESSAGE')
})

it('should report message, filename and linenumber if no stack trace but filename and lineno', function () {
var step = {
passed: false,
lineno: 45,
filename: 'source/controller.js',
message: 'MESSAGE'
}

expect(formatFailedStep(step)).toBe('MESSAGE\nsource/controller.js:45')
})
it('should properly format message containing new-line characters', function () {
// FF does not have the message in the stack trace

Expand Down

0 comments on commit cd6f060

Please sign in to comment.