fix(node/vm): use file:// URLs for absolute filenames in inspector coverage #28577
+67
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #27003.
In Vitest and other tools relying on the inspector’s
Profiler.takePreciseCoverage
,scripts executed via the Node
vm
polyfill were showing up with bare absolutepaths (e.g.
/tmp/foo.js
). Vitest filters out anything that doesn’t start withfile://
, so the “v8” coverage provider was reporting zero coverage.This patch brings the
vm
polyfill in line with Node by normalising absolutefilenames to file URLs before they’re passed down to V8. Coverage for scripts
created by
vm.runInThisContext
now reportfile:///
URLs and are picked upby coverage tooling.
A new integration test spins up an inspector session within a small
vm
scriptand asserts that a
file:///tmp/foo.js
script shows up in coverage. All codeand Markdown files were formatted and linted;
cargo fmt --check
passes.Changes
ext/node/polyfills/vm.js
:node:path
andnode:url
.filename
s tofile://
URLs before compiling.tests/testdata/inspector/vm_coverage.js
.inspector_vm_coverage_file_url
intests/integration/inspector_tests.rs
.Testing
cargo test inspector_vm_coverage_file_url -- --nocapture
Before this change the test would filter out the VM script and coverage would be empty.
After applying the patch, the test passes and the printed JSON contains an entry for
file:///tmp/foo.js
.All formatting (
cargo fmt
,deno fmt
) and linting (deno lint
) checks pass.This PR was generated by an AI system in collaboration with maintainers: @dsherret