Repository navigation
sourcesContent not correctly handled in coverage reporter with --enable-source-maps #55106
Copy link
Copy link
Closed
Closed
Copy link
Labels
coverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.regressionIssues related to regressions.Issues related to regressions.source mapsIssues and PRs related to source map support.Issues and PRs related to source map support.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Description
Version
node-v23.0.0-nightly202409243c5ceff85f
Platform
N/A
Subsystem
test_runner
What steps will reproduce the bug?
The Node.js coverage reporter does not correctly handle source maps with a custom sourcesContent and --with-source-maps.
This example was taken from the test-runner/coverage fixture:
- Generate a sourcemap via:
echo "import { test } from 'node:test';
test('ok', () => {});
function uncovered() {
return 'uncovered';
}
" | npx esbuild --sourcemap --sourcefile=stdin.test.ts --sources-content=true --bundle --platform=node --outfile="stdin.test.js"Output
// stdin.test.ts
var import_node_test = require("node:test");
(0, import_node_test.test)("ok", () => {
});
//# sourceMappingURL=stdin.test.js.map{
"version": 3,
"sources": ["stdin.test.ts"],
"sourcesContent": ["import { test } from 'node:test';\ntest('ok', () => {});\n\nfunction uncovered() {\n return 'uncovered';\n}\n\n"],
"mappings": ";AAAA,uBAAqB;AAAA,IACrB,uBAAK,MAAM,MAAM;AAAC,CAAC;",
"names": []
}- Compare the output of
node --test --experimental-test-coverage --enable-source-mapswithnode --test --experimental-test-coverage
How often does it reproduce? Is there a required condition?
Everytime
What is the expected behavior? Why is that the expected behavior?
Without --enable-source-maps:
ℹ start of coverage report
ℹ --------------------------------------------------------------
ℹ file | line % | branch % | funcs % | uncovered lines
ℹ --------------------------------------------------------------
ℹ stdin.test.ts | 57.14 | 100.00 | 100.00 | 4-6
ℹ --------------------------------------------------------------
ℹ all files | 57.14 | 100.00 | 100.00 |
ℹ --------------------------------------------------------------
ℹ end of coverage report
What do you see instead?
ℹ start of coverage report
ℹ ----------------------------------------------------------------
ℹ file | line % | branch % | funcs % | uncovered lines
ℹ ----------------------------------------------------------------
ℹ stdin.test.ts | 42.86 | 100.00 | 0.00 | 2 4-6
ℹ ----------------------------------------------------------------
ℹ all files | 42.86 | 100.00 | 0.00 |
ℹ ----------------------------------------------------------------
ℹ end of coverage report
Additional information
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
coverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.regressionIssues related to regressions.Issues related to regressions.source mapsIssues and PRs related to source map support.Issues and PRs related to source map support.test_runnerIssues and PRs related to the test runner subsystem.Issues and PRs related to the test runner subsystem.
Activity
avivkeller commentedon Sep 24, 2024
In v22.9.0, there is no difference in the output with/without
--enable-source-maps:[-]`sourcesContent` not correctly handled in coverage reporter[/-][+]`sourcesContent` not correctly handled in coverage reporter with `--enable-source-maps`[/+]geeksilva97 commentedon Sep 30, 2024
On node
v23.0.0-preI got an errorWhen executed
Error
This entry returns an
emptyobject instead ofundefinedwhich makes it to get into the condition at https://github.com/nodejs/node/blob/main/lib/internal/test_runner/test.js#L563.The coverage report is displayed anyways
Full output
geeksilva97 commentedon Oct 1, 2024
Okay, I reached the expected behavior. Let me confirm.
geeksilva97 commentedon Oct 1, 2024
I Just opened a still-drafted pr.
With source maps:
Without source maps:
test_runner: ignore unmapped lines for coverage
test_runner: ignore unmapped lines for coverage