Title: module: fix coverage of mocked CJS modules imported from ESM by marcopiraccini · Pull Request #62133 · nodejs/node · GitHub
Open Graph Title: module: fix coverage of mocked CJS modules imported from ESM by marcopiraccini · Pull Request #62133 · nodejs/node
X Title: module: fix coverage of mocked CJS modules imported from ESM by marcopiraccini · Pull Request #62133 · nodejs/node
Description: 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 passes filename to compileFunctionForCJSLoader as the V8 resource name. When the mock loader resolves a mocked module, it appends a ?node-test-mock search param to the URL. However, urlToFilename() strips this param. The coverage filter in shouldSkipFileCoverage then fails to recognize it as a mocked module. The fix passes the full url (which preserves the ?node-test-mock search param) to compileFunctionForCJSLoader instead of the stripped filename. For non-mocked CJS modules loaded via ESM, the url is file:///path/to/file.cjs which produces the same V8 behavior as passing the bare path Fixes: #61709
Open Graph Description: 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 sour...
X Description: 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 sour...
Opengraph URL: https://github.com/nodejs/node/pull/62133
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:0964f0d0-3be4-7be7-05b8-aec1410b399f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A4F2:1EF1:7068D9:993269:6A4C9411 |
| html-safe-nonce | 775b34488c6f9d6b14b831ddbba406fb00c82665746304a6c23f00741ecb8e2b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNEYyOjFFRjE6NzA2OEQ5Ojk5MzI2OTo2QTRDOTQxMSIsInZpc2l0b3JfaWQiOiIyMjE1ODY3NzE5NjM4MzU3MDA5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c0c333d90487b324fc95410a327bd72950d263621cf5e4fd97f2154cc7f7c929 |
| hovercard-subject-tag | pull_request:3364240212 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/62133/files |
| twitter:image | https://avatars.githubusercontent.com/u/668050?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/668050?s=400&v=4 |
| og:image:alt | 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 sour... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3d11bb817438277de2a940854450e83a7d32b6aeb5014e9e6b00a6423900251c |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7a2dede45637df6b92ddcfe2a557e67d4b5854ae |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width