Skip to content

Commit

Permalink
fix(reporter): Disable source maps for URLs without line number
Browse files Browse the repository at this point in the history
There is no way to resolve them in this case anyway. Fixes #1274.
  • Loading branch information
davidparsson committed Feb 18, 2016
1 parent 47066ea commit 2080221
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
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

0 comments on commit 2080221

Please sign in to comment.