GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||
GeezerVison is showing github.com — test_runner: mock dual-package with conditional exports by maruthang · Pull Request #62943 · nodejs/node Conversation
Contributor
When Resolve the specifier through Note: I was unable to run the test suite locally (no built Fixes: #58231
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsWhen `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: nodejs#58231 Signed-off-by: Maruthan G <[email protected]>
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
JakobJingleheimer
self-requested a review
|
There was an error while loading. Please reload this page.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## main #62943 +/- ## ========================================== - Coverage 89.66% 89.64% -0.03% ========================================== Files 706 706 Lines 219370 219489 +119 Branches 42065 42095 +30 ========================================== + Hits 196694 196751 +57 - Misses 14586 14638 +52 - Partials 8090 8100 +10
🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! The test is correct, and I see it's passing.
I'll do a pass on the implementation soon.
I can't remember whether http/s specifiers are still supported (I think that was maybe removed?).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It used to be experimental, but i believe it was removed a few majors ago. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Confirming what @ljharb said — For this PR specifically, that means the Happy to drop those two checks as a follow-up cleanup commit, or keep them as belt-and-braces defense — your call. The other branches ( |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
My call is #62943 (comment)
🙂 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🙌 Thanks!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
|
Landed in 9d94b65 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
When `mock.module()` targets a package whose `exports` field maps `import` and `require` to different files, the ESM resolver and the CJS resolver disagree on the resolved path. Only the ESM path was registered in `mockMap`, so `require()` of the mocked specifier bypassed the mock and loaded the real CJS module. Resolve the specifier through `Module._resolveFilename` from the caller's directory in addition to the existing ESM resolution. When the two paths differ, register the CJS path as a second key in `mockMap` and invalidate `Module._cache[cjsPath]`, restoring it on `restore()`. Single-resolution packages keep their existing behavior. Fixes: #58231 Signed-off-by: Maruthan G <[email protected]> PR-URL: #62943 Reviewed-By: Aviv Keller <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
…971) Node 24.21.0 (nodejs/node#62943) makes mock.module() also intercept require() of dual CJS/ESM packages. The skipped mock-contract suite replaced ethers with only { Wallet, Contract }, so loading resyncing-nonce-manager.js threw 'Class extends value undefined' when extending ethers.NonceManager, failing main's nightly CI since the runners picked up 24.21. Signed-off-by: Andres Olave <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
test-runner:requireing a mocked dual-package gets the original instead of the mock
There was an error while loading. Please reload this page.