René's URL Explorer Experiment


Title: test-runner: `require`ing a mocked dual-package gets the original instead of the mock · Issue #58231 · nodejs/node · GitHub

Open Graph Title: test-runner: `require`ing a mocked dual-package gets the original instead of the mock · Issue #58231 · nodejs/node

X Title: test-runner: `require`ing a mocked dual-package gets the original instead of the mock · Issue #58231 · nodejs/node

Description: Version 22.15 Platform Darwin MacBook-Pro.local 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64 Subsystem node:mock What steps will reproduce the bug? The issue is fo...

Open Graph Description: Version 22.15 Platform Darwin MacBook-Pro.local 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64 Subsystem node:mock What steps...

X Description: Version 22.15 Platform Darwin MacBook-Pro.local 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64 Subsystem node:mock What steps...

Opengraph URL: https://github.com/nodejs/node/issues/58231

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"test-runner: `require`ing a mocked dual-package gets the original instead of the mock","articleBody":"### Version\n\n22.15\n\n### Platform\n\n```text\nDarwin MacBook-Pro.local 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64\n```\n\n### Subsystem\n\nnode:mock\n\n### What steps will reproduce the bug?\n\n\nThe issue is for packages that expose esm `module` and cjs `main`.  See Repo: https://github.com/sloops77/node-mock-bug for more examples\n\nRather than create my own package the examples below use the `nanoid` 3.x package. The linked repo also shows that it is reproducible for the ethers package (which also exposes `module` and `main`).\n\n```json\n// snippet of package.json from nanoid\n{\n  \"name\": \"nanoid\",\n  \"version\": \"3.3.11\",\n  \"description\": \"A tiny (116 bytes), secure URL-friendly unique string ID generator\",\n  \"type\": \"module\",\n  \"main\": \"index.cjs\",\n  \"module\": \"index.js\",\n  ...\n```\n\n```js\n// test.js\nconst {describe, it, mock} = require(\"node:test\");\nconst assert = require(\"node:assert\");\n\nmock.module('nanoid', {\n  namedExports: {\n    nanoid() {\n      return '1234'\n    }\n  },\n});\n\n\ntest('mocking problem in cjs', () => {\n  const {nanoid} = require('nanoid')\n  assert.strictEqual(nanoid(), '1234'); // fails test because cjs is not mocked\n})\n\ntest('mocking works for esm', async () => {\n  const {nanoid} = await import('nanoid')\n  assert.strictEqual(nanoid(), '1234'); // works as it should\n})\n\n```\n\n\n### How often does it reproduce? Is there a required condition?\n\n1. For imported packages it seems 100% consistent. It also occurs for a module mock that uses `defaultExport`.\n2. Node core modules do not reproduce this issue\n\n### What is the expected behavior? Why is that the expected behavior?\n\nCJS & MJS files should receive a mocked module\n\n### What do you see instead?\n\nCJS files receive the original module, not the mock. MJS files are fine as they receive the mock.\n\n### Additional information\n\n_No response_","author":{"url":"https://github.com/sloops77","@type":"Person","name":"sloops77"},"datePublished":"2025-05-08T11:30:49Z","url":"https://github.com/nodejs/node/issues/58231"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:16144e33-9375-5dec-626f-22cc76a2a61b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDADE:20A3B4:55BCD7:7523EB:6AED5BC8
html-safe-nonce7f5fb98b379bab9e4dd2e4124ed433420cb736e14c1f838a4dad5062c9780ddf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQURFOjIwQTNCNDo1NUJDRDc6NzUyM0VCOjZBRUQ1QkM4IiwidmlzaXRvcl9pZCI6Ijg1NDAwNjAwMTE5MTg2MTM0NDgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacfbf6ad44bd620bdba34b1d8926d5a8349ce9df6b5d0bae3ad15af59dc83bda4c
hovercard-subject-tagissue:3048706674
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/58231/issue_layout
twitter:imagehttps://opengraph.githubassets.com/552d816fe304d9f06a1ba16919a6bbad4fd58208a7fb5fa2a06cd6f03e16a6d6/nodejs/node/issues/58231
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/552d816fe304d9f06a1ba16919a6bbad4fd58208a7fb5fa2a06cd6f03e16a6d6/nodejs/node/issues/58231
og:image:altVersion 22.15 Platform Darwin MacBook-Pro.local 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:33:47 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T6000 arm64 Subsystem node:mock What steps...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamesloops77
hostnamegithub.com
expected-hostnamegithub.com
None56fb42677ae87ed3e64410323d67980aa65d0485568a7858f874e7edfc6d1c11
turbo-cache-controlno-preview
go-importgithub.com/nodejs/node git https://github.com/nodejs/node.git
octolytics-dimension-user_id9950313
octolytics-dimension-user_loginnodejs
octolytics-dimension-repository_id27193779
octolytics-dimension-repository_nwonodejs/node
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id27193779
octolytics-dimension-repository_network_root_nwonodejs/node
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release9c9a37e2423ed382cf39f70b5aa4b4858b40a3b0
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/nodejs/node/issues/58231#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F58231
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fnodejs%2Fnode%2Fissues%2F58231
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=nodejs%2Fnode
Reloadhttps://github.com/nodejs/node/issues/58231
Reloadhttps://github.com/nodejs/node/issues/58231
Reloadhttps://github.com/nodejs/node/issues/58231
nodejshttps://github.com/nodejs
nodehttps://github.com/nodejs/node
Codehttps://github.com/nodejs/node
Issues654 (654)https://github.com/nodejs/node/issues
Pull requests662 (662)https://github.com/nodejs/node/pulls
Actionshttps://github.com/nodejs/node/actions
Projectshttps://github.com/nodejs/node/projects
Security and qualityhttps://github.com/nodejs/node/security
Insightshttps://github.com/nodejs/node/pulse
https://github.com/nodejs/node
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/58231
New issuehttps://github.com/login?return_to=https://github.com/nodejs/node/issues/58231
test-runner: requireing a mocked dual-package gets the original instead of the mockhttps://github.com/nodejs/node/issues/58231#top
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
test_runnerIssues and PRs related to the test runner subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner%22
test_runner-agendaIssues and PRs to discuss during Test Runner team meetings.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner-agenda%22
https://github.com/sloops77
sloops77https://github.com/sloops77
on May 8, 2025https://github.com/nodejs/node/issues/58231#issue-3048706674
https://github.com/sloops77/node-mock-bughttps://github.com/sloops77/node-mock-bug
Nexthttps://github.com/nodejs/node/issues/58231?timeline_page=1
https://github.com/sloops77
sloops77https://github.com/sloops77
on May 8, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2862719423
#53634https://github.com/nodejs/node/issues/53634
https://github.com/ljharb
ljharbhttps://github.com/ljharb
on May 8, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2863544770
https://github.com/sloops77
sloops77https://github.com/sloops77
on May 10, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2869163150
@ljharbhttps://github.com/ljharb
sloops77https://github.com/sloops77
on May 10, 2025https://github.com/nodejs/node/issues/58231#event-17603528473
https://github.com/sloops77
sloops77https://github.com/sloops77
on May 23, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2903155797
@ljharbhttps://github.com/ljharb
https://github.com/remix-run/react-routerhttps://github.com/remix-run/react-router
https://github.com/sloops77
sloops77https://github.com/sloops77
on Jun 4, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2941339510
@JakobJingleheimerhttps://github.com/JakobJingleheimer
@cjihrighttps://github.com/cjihrig
https://github.com/JakobJingleheimer
JakobJingleheimerhttps://github.com/JakobJingleheimer
on Jun 5, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2943005424
https://github.com/joyeecheung
joyeecheunghttps://github.com/joyeecheung
on Jun 5, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2943882904
https://github.com/JakobJingleheimer
JakobJingleheimerhttps://github.com/JakobJingleheimer
on Jun 5, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2943940126
https://github.com/sloops77
sloops77https://github.com/sloops77
on Jun 6, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2947574565
@JakobJingleheimerhttps://github.com/JakobJingleheimer
@joyeecheunghttps://github.com/joyeecheung
https://github.com/sloops77
sloops77https://github.com/sloops77
on Jun 10, 2025https://github.com/nodejs/node/issues/58231#issuecomment-2960566115
@JakobJingleheimerhttps://github.com/JakobJingleheimer
ljharbhttps://github.com/ljharb
test_runnerIssues and PRs related to the test runner subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner%22
on Jun 10, 2025https://github.com/nodejs/node/issues/58231#event-18082772164
https://github.com/sloops77
sloops77https://github.com/sloops77
on Aug 20, 2025https://github.com/nodejs/node/issues/58231#issuecomment-3203965063
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Apr 20, 2026https://github.com/nodejs/node/issues/58231#issuecomment-4277370901
GitHub Actionshttps://help.github.com/en/actions
github-actionshttps://github.com/apps/github-actions
staleIssues and PRs marked stale due to inactivity and scheduled for automatic closure.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22stale%22
on Apr 20, 2026https://github.com/nodejs/node/issues/58231#event-24659029221
https://github.com/JakobJingleheimer
JakobJingleheimerhttps://github.com/JakobJingleheimer
on Apr 22, 2026https://github.com/nodejs/node/issues/58231#issuecomment-4300189231
https://github.com/JakobJingleheimer/req-esm-mockhttps://github.com/JakobJingleheimer/req-esm-mock
repro without-pjson-exportshttps://github.com/JakobJingleheimer/req-esm-mock/tree/without-pjson-exports
JakobJingleheimerhttps://github.com/JakobJingleheimer
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
on Apr 22, 2026https://github.com/nodejs/node/issues/58231#event-24773259524
JakobJingleheimerhttps://github.com/JakobJingleheimer
Test Runner Boardhttps://github.com/orgs/nodejs/projects/14
on Apr 22, 2026https://github.com/nodejs/node/issues/58231#event-24773263976
JakobJingleheimerhttps://github.com/JakobJingleheimer
Test Runner Boardhttps://github.com/orgs/nodejs/projects/14
on Apr 22, 2026https://github.com/nodejs/node/issues/58231
JakobJingleheimerhttps://github.com/JakobJingleheimer
on Apr 22, 2026https://github.com/nodejs/node/issues/58231#event-24773406618
JakobJingleheimerhttps://github.com/JakobJingleheimer
Test Runner Boardhttps://github.com/orgs/nodejs/projects/14
on Apr 22, 2026https://github.com/nodejs/node/issues/58231
JakobJingleheimerhttps://github.com/JakobJingleheimer
test_runner-agendaIssues and PRs to discuss during Test Runner team meetings.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner-agenda%22
on Apr 22, 2026https://github.com/nodejs/node/issues/58231#event-24773444999
trivikrhttps://github.com/trivikr
completedhttps://github.com/nodejs/node/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
9d94b65https://github.com/nodejs/node/commit/9d94b6548a8c3c18e5985ce2aef84b2bd8ea9ce0
on Aug 21, 2026https://github.com/nodejs/node/issues/58231#event-29825782406
github-project-automationhttps://github.com/apps/github-project-automation
Test Runner Boardhttps://github.com/orgs/nodejs/projects/14
on Aug 21, 2026https://github.com/nodejs/node/issues/58231
arynhhttps://github.com/arynh
on Aug 21, 2026https://github.com/nodejs/node/issues/58231#event-29825824650
test_runner: mock dual-package with conditional exportshttps://github.com/arynh/node/commit/9d94b6548a8c3c18e5985ce2aef84b2bd8ea9ce0
9d94b65https://github.com/arynh/node/commit/9d94b6548a8c3c18e5985ce2aef84b2bd8ea9ce0
aduh95https://github.com/aduh95
on Aug 25, 2026https://github.com/nodejs/node/issues/58231#event-30010185667
test_runner: mock dual-package with conditional exportshttps://github.com/nodejs/node/commit/d384603751369c7244185f708a9ee7929e3f1f12
d384603https://github.com/nodejs/node/commit/d384603751369c7244185f708a9ee7929e3f1f12
test_runner: mock dual-package with conditional exportshttps://github.com/nodejs/node/commit/797ef40d23609314ba0266cd87d80f8c24dd07ff
797ef40https://github.com/nodejs/node/commit/797ef40d23609314ba0266cd87d80f8c24dd07ff
test_runner: mock dual-package with conditional exportshttps://github.com/nodejs/node/commit/a59febb84c8adedc65fe64d73f2de54d324e77f3
a59febbhttps://github.com/nodejs/node/commit/a59febb84c8adedc65fe64d73f2de54d324e77f3
aduh95https://github.com/aduh95
on Sep 7, 2026https://github.com/nodejs/node/issues/58231#event-30681668049
test_runner: mock dual-package with conditional exportshttps://github.com/nodejs/node/commit/6f91d0916e36cca61efb3d321c3b97cabccdc6a5
6f91d09https://github.com/nodejs/node/commit/6f91d0916e36cca61efb3d321c3b97cabccdc6a5
test_runner: mock dual-package with conditional exportshttps://github.com/nodejs/node/commit/339acf4201932c3db4ec428bdd0ddb8ba7a8f577
339acf4https://github.com/nodejs/node/commit/339acf4201932c3db4ec428bdd0ddb8ba7a8f577
Sign up for freehttps://github.com/signup?return_to=https://github.com/nodejs/node/issues/58231
Sign in to commenthttps://github.com/login?return_to=https://github.com/nodejs/node/issues/58231
confirmed-bugIssues and PRs for confirmed bugs.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22confirmed-bug%22
test_runnerIssues and PRs related to the test runner subsystem.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner%22
test_runner-agendaIssues and PRs to discuss during Test Runner team meetings.https://github.com/nodejs/node/issues?q=state%3Aopen%20label%3A%22test_runner-agenda%22
Test Runner Boardhttps://github.com/orgs/nodejs/projects/14
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.