Skip to content

Commit

Permalink
fix: handle sourcemap sources emtpy edge case (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
j03m committed Mar 27, 2020
1 parent 27de734 commit 628af48
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/v8-to-istanbul.js
Expand Up @@ -73,7 +73,7 @@ module.exports = class V8ToIstanbul {

_rewritePath (rawSourceMap) {
const sourceRoot = rawSourceMap.sourcemap.sourceRoot ? rawSourceMap.sourcemap.sourceRoot.replace('file://', '') : ''
const sourcePath = rawSourceMap.sourcemap.sources[0].replace('file://', '')
const sourcePath = rawSourceMap.sourcemap.sources.length >= 1 ? rawSourceMap.sourcemap.sources[0].replace('file://', '') : rawSourceMap.sourcemap.file
const candidatePath = join(sourceRoot, sourcePath)

if (isAbsolute(candidatePath)) {
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/scripts/empty.compiled.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/fixtures/scripts/empty.compiled.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added test/fixtures/scripts/empty.js
Empty file.
20 changes: 18 additions & 2 deletions test/v8-to-istanbul.js
@@ -1,5 +1,4 @@
/* global describe, it */

/* global describe, it, beforeEach, afterEach */
const { readdirSync, lstatSync, writeFileSync, readFileSync } = require('fs')
const path = require('path')
const runFixture = require('./utils/run-fixture')
Expand Down Expand Up @@ -90,6 +89,23 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
v8ToIstanbul.sourceTranspiled.should.not.be.undefined()
})
})
describe('source map format edge cases', () => {
let consoleWarn
beforeEach(() => {
consoleWarn = console.warn
console.warn = () => { throw new Error('Test should not invoke console.warn') }
})
afterEach(() => {
console.warn = consoleWarn
})
it('should handle empty sources in a sourcemap', async () => {
const v8ToIstanbul = new V8ToIstanbul(
`file://${require.resolve('./fixtures/scripts/empty.compiled.js')}`,
0
)
await v8ToIstanbul.load()
})
})

// execute JavaScript files in fixtures directory; these
// files contain the raw v8 output along with a set of
Expand Down

0 comments on commit 628af48

Please sign in to comment.