diff --git a/lib/reporter.js b/lib/reporter.js index fca44ec85..dab5574cb 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -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) diff --git a/test/unit/reporter.spec.js b/test/unit/reporter.spec.js index d946d78a7..d2c32edf4 100644 --- a/test/unit/reporter.spec.js +++ b/test/unit/reporter.spec.js @@ -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') } @@ -93,6 +96,10 @@ describe('reporter', () => { } } + beforeEach(() => { + originalPositionForCallCount = 0 + }) + MockSourceMapConsumer.GREATEST_LOWER_BOUND = 1 MockSourceMapConsumer.LEAST_UPPER_BOUND = 2 @@ -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