Repository navigation
Bad error message in --experimental-test-coverage output when a source maps source module is missing #54756
Copy link
Copy link
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.coverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.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
Activity
- addedcoverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.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.
on Sep 4, 2024 See also #54444, which resolved a similar error, so maybe they are somewhat related?
If someone wants to pick this up, this diff plus the test case provided in the bug report should get you started:
diff --git a/lib/internal/test_runner/coverage.js b/lib/internal/test_runner/coverage.js index 7ef5702072..4348ea06c3 100644 --- a/lib/internal/test_runner/coverage.js +++ b/lib/internal/test_runner/coverage.js @@ -388,8 +388,12 @@ class TestCoverage { continue; } - newUrl ??= startEntry?.originalSource; - const mappedLines = this.getLines(newUrl); + const mappedLines = this.getLines(startEntry.originalSource); + if (!mappedLines) { + throw new Error('insert better error message here'); + } + + newUrl ??= startEntry.originalSource; const mappedStartOffset = this.entryToOffset(startEntry, mappedLines); const mappedEndOffset = this.entryToOffset(endEntry, mappedLines) + 1; for (let l = startEntry.originalLine; l <= endEntry.originalLine; l++) {
throw new Error('insert better error message here');
What even is the issue? Is it:
a particular source module at a path is missing
In that snippet,
startEntry.originalSourceis the name of a file that does not exist for whatever reason.getLines()handles this case, but this code didn't properly check the return value.- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Sep 20, 2024 Working on this now.
Reacted by Pietro Marchini and Jayden Seric
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.coverageIssues and PRs related to Node.js code coverage support.Issues and PRs related to Node.js code coverage support.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.
Version
v22.8.0
Platform
Subsystem
No response
What steps will reproduce the bug?
In
dist/a.mjs:In
dist/a.mjs.map:In
test.mjs:Then, run:
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior? Why is that the expected behavior?
An error message reported after the tests output, explaining that a particular source module at a path is missing. If multiple are missing, then output the list of missing paths.
What do you see instead?
Additional information
This scenario comes up very frequently when working in a TypeScript project with source maps enabled, that has
srcanddistdirectories. Often you have a build script watching thesrcdirectory, and as you work you rename or delete a source module. The result is that old artifacts don't get cleaned in thedistdirectory, but the next time the tests run on thedistdirectory the coverage explodes with the error this issue reports.Note that if multiple test modules run, then the coverage report for everything is obscured by the error message: