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(reporter): Disable source maps for URLs without line number #1915

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var createErrorFormatter = function (basePath, emitter, SourceMapConsumer) {

var file = findFile(path)

if (file && file.sourceMap) {
if (file && file.sourceMap && line) {
line = parseInt(line || '0', 10)

column = parseInt(column, 10)
Expand Down
23 changes: 23 additions & 0 deletions test/unit/reporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,15 @@ describe('reporter', () => {
})

describe('source maps', () => {
var originalPositionForCallCount = 0

class MockSourceMapConsumer {
constructor (sourceMap) {
this.source = sourceMap.content.replace('SOURCE MAP ', '/original/')
}

originalPositionFor (position) {
originalPositionForCallCount++
if (position.line === 0) {
throw new TypeError('Line must be greater than or equal to 1, got 0')
}
Expand All @@ -93,6 +96,10 @@ describe('reporter', () => {
}
}

beforeEach(() => {
originalPositionForCallCount = 0
})

MockSourceMapConsumer.GREATEST_LOWER_BOUND = 1
MockSourceMapConsumer.LEAST_UPPER_BOUND = 2

Expand Down Expand Up @@ -156,6 +163,22 @@ describe('reporter', () => {
})
})

it('should not try to use source maps when no line is given', done => {
formatError = m.createErrorFormatter('/some/base', emitter, MockSourceMapConsumer)
var servedFiles = [new File('/some/base/a.js'), new File('/some/base/b.js')]
servedFiles[0].sourceMap = {content: 'SOURCE MAP a.js'}
servedFiles[1].sourceMap = {content: 'SOURCE MAP b.js'}

emitter.emit('file_list_modified', {served: servedFiles})

_.defer(() => {
var ERROR = 'at http://localhost:123/base/b.js'
expect(formatError(ERROR)).to.equal('at /some/base/b.js\n')
expect(originalPositionForCallCount).to.equal(0)
done()
})
})

describe('Windows', () => {
formatError = null
var servedFiles = null
Expand Down