Title: doc: add note (and caveat) for `mock.module` about customization hooks by JakobJingleheimer · Pull Request #62075 · nodejs/node · GitHub
Open Graph Title: doc: add note (and caveat) for `mock.module` about customization hooks by JakobJingleheimer · Pull Request #62075 · nodejs/node
X Title: doc: add note (and caveat) for `mock.module` about customization hooks by JakobJingleheimer · Pull Request #62075 · nodejs/node
Description: So for instance, if mocking a tsx module and a loader was registered via the async API (module.register(), --loader, etc), the test-runner doesn't use it and throws trying to validate format (even though it will actually work): node/lib/internal/test_runner/mock/mock.js Lines 650 to 653 in f8d5bad const { format, url } = sharedState.moduleLoader.resolveSync(caller, request); debug('module mock, url = "%s", format = "%s", caller = "%s"', url, format, caller); if (format) { // Format is not yet known for ambiguous files when detection is enabled. validateOneOf(format, 'format', kSupportedFormats); This is mainly problem within the ModuleLoader itself, which checks whether sync hooks exist; when they do, it uses that chain and ignores the potential existence of registered async hooks: node/lib/internal/modules/esm/loader.js Lines 727 to 734 in f8d5bad resolveSync(parentURL, request) { const specifier = `${request.specifier}`; const importAttributes = request.attributes ?? kEmptyObject; if (syncResolveHooks.length) { // Has module.registerHooks() hooks, chain the asynchronous hooks in the default step. return resolveWithSyncHooks(specifier, parentURL, importAttributes, this.#defaultConditions, this.#resolveAndMaybeBlockOnLoaderThread.bind(this)); The problem for the test runner was created/exposed by switching the test-runner's loader to sync registration, which ensures there's always a sync chain (causing the async chain to be ignored internally). Geoffrey, Joyee, Matteo, and I discussed this scenario ~a year ago in Dublin. The fix is not simple. It would need to do something like this slack convo
Open Graph Description: So for instance, if mocking a tsx module and a loader was registered via the async API (module.register(), --loader, etc), the test-runner doesn't use it and throws trying to validate format (e...
X Description: So for instance, if mocking a tsx module and a loader was registered via the async API (module.register(), --loader, etc), the test-runner doesn't use it and throws trying to validate forma...
Opengraph URL: https://github.com/nodejs/node/pull/62075
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:25df9710-4287-8cca-5e92-f5a00fb648d7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | AAD4:53D51:1CAB816:29408A5:6A4CE5C9 |
| html-safe-nonce | 733818612ffbe3e9c6245bccda8f957a4d69efbd0d58be1fccf3a148a76eea95 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUQ0OjUzRDUxOjFDQUI4MTY6Mjk0MDhBNTo2QTRDRTVDOSIsInZpc2l0b3JfaWQiOiI5MjExNjUyMTMzNzQ0MzM4Mzc4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | cd1aa6c5afd2ac1983ad42ba4e6606e9973585fcb9f7c207fdc52bcdfb902cd7 |
| hovercard-subject-tag | pull_request:3345012818 |
| 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/62075/files |
| twitter:image | https://avatars.githubusercontent.com/u/3012099?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3012099?s=400&v=4 |
| og:image:alt | So for instance, if mocking a tsx module and a loader was registered via the async API (module.register(), --loader, etc), the test-runner doesn't use it and throws trying to validate format (e... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8 |
| 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 |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c5a57f04eeb310f57c73fd6d751d957e2ca27ed2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width