module: fix coverage of mocked CJS modules imported from ESM#62133
Open
marcopiraccini wants to merge 1 commit intonodejs:mainfrom
Open
module: fix coverage of mocked CJS modules imported from ESM#62133marcopiraccini wants to merge 1 commit intonodejs:mainfrom
marcopiraccini wants to merge 1 commit intonodejs:mainfrom
Conversation
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
Collaborator
|
Review requested:
|
jsumners-nr
approved these changes
Mar 6, 2026
Collaborator
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #62133 +/- ##
==========================================
- Coverage 89.65% 89.65% -0.01%
==========================================
Files 676 676
Lines 206231 206410 +179
Branches 39505 39530 +25
==========================================
+ Hits 184898 185049 +151
- Misses 13463 13475 +12
- Partials 7870 7886 +16
🚀 New features to boost your workflow:
|
marco-ippolito
approved these changes
Mar 6, 2026
himself65
approved these changes
Mar 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
When a CommonJS module is mocked via
mock.module()and imported from an ESM module, the mocked module incorrectly appears in the coverage report with partial coverage, even though the original source was never executed.The root cause is in
loadCJSModule. It passesfilenametocompileFunctionForCJSLoaderas the V8 resource name.When the mock loader resolves a mocked module, it appends a
?node-test-mocksearch param to the URL. However,urlToFilename()strips this param. The coverage filter inshouldSkipFileCoveragethen fails to recognize it as a mocked module.The fix passes the full
url(which preserves the?node-test-mocksearch param) tocompileFunctionForCJSLoaderinstead of the strippedfilename. For non-mocked CJS modules loaded via ESM, theurlisfile:///path/to/file.cjswhich produces the same V8 behavior as passing the bare pathFixes: #61709