Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On error in beforeAll/afterAll relevant information to debug are miss… #232

Merged
merged 3 commits into from Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/adapter.js
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
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