Skip to content

Commit

Permalink
fix: handle relative sourceRoots in source map files (#100)
Browse files Browse the repository at this point in the history
Co-authored-by: jmordetsky@bloomberg.net <jmordetsky@bloomberg.net>
  • Loading branch information
j03m and j03m committed May 6, 2020
1 parent 714f84d commit 16ad3aa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/v8-to-istanbul.js
Expand Up @@ -79,7 +79,7 @@ module.exports = class V8ToIstanbul {
if (isAbsolute(candidatePath)) {
this.path = candidatePath
} else {
this.path = resolve(dirname(this.path), sourcePath)
this.path = resolve(dirname(this.path), candidatePath)
}
}

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions test/fixtures/scripts/relative-source-root.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/relative-source-root.compiled.js.map

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

6 changes: 6 additions & 0 deletions test/source.js
Expand Up @@ -32,6 +32,12 @@ describe('Source', () => {
source.relativeToOffset(2, 50).should.equal(22)
source.relativeToOffset(1, Infinity).should.equal(1)
})

it('returns empty object for out of range params', () => {
const sourceRaw = ''
const source = new CovSource(sourceRaw, 0)
source.offsetToOriginalRelative(undefined, Infinity, Infinity).should.deepEqual({})
})
})

describe('ignore', () => {
Expand Down
9 changes: 9 additions & 0 deletions test/v8-to-istanbul.js
Expand Up @@ -136,6 +136,15 @@ ${'//'}${'#'} sourceMappingURL=data:application/json;base64,${base64Sourcemap}
)
await v8ToIstanbul.load()
})

it('should handle relative sourceRoots correctly', async () => {
const v8ToIstanbul = new V8ToIstanbul(
`file://${require.resolve('./fixtures/scripts/relative-source-root.compiled.js')}`,
0
)
await v8ToIstanbul.load()
assert(v8ToIstanbul.path.includes('v8-to-istanbul/test/fixtures/one-up/relative-source-root.js'))
})
})

// execute JavaScript files in fixtures directory; these
Expand Down

0 comments on commit 16ad3aa

Please sign in to comment.