Repository navigation
--experimental-test-coverage falsely reports missing coverage where TS source is import type #54753
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.strip-typesIssues and PRs related to TypeScript type stripping.Issues and PRs related to TypeScript type stripping.
on Sep 4, 2024 I'm not sure, but maybe inspiration can be taken from istanbuljs/v8-to-istanbul#244 .
Reacted by Ari Perkkiö- removedstrip-typesIssues and PRs related to TypeScript type stripping.Issues and PRs related to TypeScript type stripping.
on Sep 5, 2024 Seems like a bug to me as well. not sure where is the correct place to fix
- addedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Sep 20, 2024 (This issue isn't fixed by the linked PR #55037, I've fixed it~sorry for the confusion)
Hey, I'm thinking this over, and technically the
import type ...is uncovered, as it's not used anywhere at Runtime. If you look at:{ "version": 3, "sources": ["index.mts"], "sourcesContent": ["invalidJSSyntax;\n\nconsole.log(\"Hi\");"], "mappings": "AAEA,QAAQ,IAAI,IAAI", "names": [] }invalidJSSyntaxshould return that it is uncovered, right? Well...import typeis similar, no?- removedconfirmed-bugIssues and PRs for confirmed bugs.Issues and PRs for confirmed bugs.
on Oct 9, 2024 1 remaining item
Reopening due to #55339. I've removed confirmed-bug
Issues and PRs for confirmed bugs. as the "fix" for this issue, that is, not checking coverage on un-transpiled lines, doesn't seem to be viable.IMHO this is expected behavior, as, while annoying, this line is technically not covered.
Reacted by Edy Silvagithub-actions commented
on Apr 28, 2026 on Apr 28, 2026 – with GitHub ActionsContributorMore actionsThis issue has been marked as stale due to 210 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.- addedstaleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.Issues and PRs marked stale due to inactivity and scheduled for automatic closure.
on Apr 28, 2026 - added a commit that references this issue
on May 23, 2026 - added a commit that references this issue
on May 28, 2026 - added 2 commits that reference this issue
on May 30, 2026 - added a commit that references this issue
on Jul 30, 2026
Version
v22.8.0
Platform
Subsystem
No response
What steps will reproduce the bug?
With this TypeScript source code in
src/a.mts(where the import is from doesn't matter):Compiling that to
dist/a.mjs:With source map
dist/a.mjs.map:Then in
test.mjs:Run:
How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior? Why is that the expected behavior?
100% code coverage reported for the module
src/a.mts.What do you see instead?
Notice the false missing line coverage reported in the terminal output:
Additional information
If you comment out the
import type {} from "node:assert";and rebuild, a second run for functionally the same runtime code now correctly reports no missing coverage:If you don't create source maps when compiling TypeScript modules containing
import type, the Node.js test runner correctly reports no missing coverage. So the problem is around how Node.js is interpreting the source maps. Only runtime code should determine code coverage; not source code like TypeScriptimport typethat is eliminated in the build.Something else that is strange, is that the Node.js CLI flag
--enable-source-mapsdoesn't seem to have an effect on how the Node.js test runner reports coverage; even without the flag it will always take into account the source maps information. Why is coverage exempt from respecting how--enable-source-mapsworks for other Node.js features?