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: handle relative sourceRoots in source map files #100

Merged
merged 1 commit into from May 6, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test covers a previously uncovered return statement for out of range issues in offsetToOriginalRelative. Added to bump a rounding error out of the previous build.

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