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

V8 source map cache is not used on Windows #300

Closed
clemyan opened this issue Apr 27, 2021 · 0 comments · Fixed by #301
Closed

V8 source map cache is not used on Windows #300

clemyan opened this issue Apr 27, 2021 · 0 comments · Fixed by #301

Comments

@clemyan
Copy link
Contributor

clemyan commented Apr 27, 2021

  • Version: v16.0.0, v15.14.0
  • Platform: Windows 10 64-bit

Summary

Somewhere along the node v15 line, V8 coverage data output by node changed format on Windows. Specifically, file URLs within the source-map-cache changed from

file://C:\some\path\main.js

to

file:///C:/some/path/main.js

(Note the extra forward slash in front)

I haven't bisected further but v15.0.0 is using backslashes and v15.14.0 is using forward slashes.

This makes _getSourceMap unable to correctly get cached source maps (since it searches using backslashes but keys in the sourceMapCache use forward slashes).

Symptoms

This directly affects use cases where the source maps are virtual (e.g. ts-node), causing c8 to report incorrect locations for uncovered code. Worse-case scenario is when the reported range is outside of the original source size (e.g. position 1000 in generated code is uncovered but original source is only 500 bytes), in which case the uncovered branch/function/line is silently discarded.

This also affects cases where source maps are not virtual (i.e. exist in actual fs), but in an unexpected way. v8-to-instanbul is also affected by a similar bug, and would throw when given a source map with file URL as source paths. However, since c8 cannot find the source map, no source maps are passed to v8-to-instanbul, avoiding the buggy code path.

Reproduction

Run the following file with c8 and ts-node

export default () => {
	console.log('uncovered')
}

// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Node v14.16.1 & v15.0.0 result:

image

Node v15.14.0 & v16.0.0 result:

image

Fix

This can be fixed by normalizing file URLs in the source-map-cache to (and always querying the sourceMapCache using) forward slashes, with url.fileURLToPath and url.pathToFileURL.

This, however, breaks some test due to the v8-to-instanbul bug noted above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant