You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
exportdefault()=>{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:
Node v15.14.0 & v16.0.0 result:
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.
The text was updated successfully, but these errors were encountered:
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 fromto
(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 thesourceMapCache
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
Node v14.16.1 & v15.0.0 result:
Node v15.14.0 & v16.0.0 result:
Fix
This can be fixed by normalizing file URLs in the
source-map-cache
to (and always querying thesourceMapCache
using) forward slashes, withurl.fileURLToPath
andurl.pathToFileURL
.This, however, breaks some test due to the v8-to-instanbul bug noted above.
The text was updated successfully, but these errors were encountered: