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

fix(adapter): don't duplicate multiline failure messages #294

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,23 @@ 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 stackframes = step.stack.split('\n')

// Jasmine filters empty newlines from the stack so remove them from the
// message before searching for it. Also, also remove the trailing newline (if
// present) so that when the message is put back on the top of the stack it
// doesn't introduce an extra newline.
var messageWithoutEmptyLines = step.message.replace(/\n+/g, '\n').replace(/\n$/, '')
var messageStartIndex = step.stack.indexOf(messageWithoutEmptyLines)
var firstNewlineIndex = step.stack.indexOf('\n')
var messageOnStack = null
if (stackframes[0].indexOf(step.message) !== -1) {
var stack = step.stack
if (messageStartIndex !== -1 && messageStartIndex < firstNewlineIndex) {
// Remove the message if it is in the stack string (eg Chrome)
messageOnStack = stackframes.shift()
messageOnStack = step.stack.substring(0, messageStartIndex + messageWithoutEmptyLines.length)
stack = step.stack.substring(messageStartIndex + messageWithoutEmptyLines.length)
}

var stackframes = stack.split('\n')
// Filter frames
var relevantStackFrames = getRelevantStackFrom(stackframes)
if (messageOnStack) {
Expand Down
15 changes: 13 additions & 2 deletions test/adapter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe('jasmine adapter', function () {
stack: '@file.js:123\n'
}

expect(formatFailedStep(step)).toMatch(/^Jasmine fail message/)
expect(formatFailedStep(step)).toBe('Jasmine fail message\n@file.js:123')
})

it('should report message if no stack trace', function () {
Expand All @@ -383,6 +383,7 @@ describe('jasmine adapter', function () {

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 All @@ -392,7 +393,17 @@ describe('jasmine adapter', function () {
stack: 'Error: Jasmine fail\nmessage\n@file.js:123'
}

expect(formatFailedStep(step)).toMatch('Jasmine fail\nmessage\n@file.js:123')
expect(formatFailedStep(step)).toBe('Error: Jasmine fail\nmessage\n@file.js:123')
})

it('should properly format message containing repeated new-line characters', function () {
var step = {
passed: false,
message: 'Failed: 1. failure message\n\n\n2. another failure\n3. a third failure\n\n\n\n',
stack: 'Error: Failed: 1. failure message\n2. another failure\n3. a third failure\n at <Jasmine>\n at UserContext.<anonymous> (/base/jasmine/test.js:13:9)\n at <Jasmine>'
}

expect(formatFailedStep(step)).toBe('Error: Failed: 1. failure message\n2. another failure\n3. a third failure\n at <Jasmine>\n at UserContext.<anonymous> (/base/jasmine/test.js:13:9)\n at <Jasmine>')
})
})

Expand Down