node/test/es-module
Joyee Cheung 2e91b28aaf
module: handle null source from async loader hooks in sync hooks
This relaxes the validation in sync hooks so that it accepts
the quirky nullish source returned by the default step of the
async loader when the module being loaded is CommonJS.
When there are no customization hooks registered, a saner
synchronous default load step is used to use a property
instead of a reset nullish source to signify that the module
should go through the CJS monkey patching routes and reduce
excessive reloading from disk.

PR-URL: https://github.com/nodejs/node/pull/59929
Backport-PR-URL: https://github.com/nodejs/node/pull/62029
Fixes: https://github.com/nodejs/node/issues/59384
Fixes: https://github.com/nodejs/node/issues/57327
Refs: https://github.com/nodejs/node/issues/59666
Refs: https://github.com/dygabo/load_module_test
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Fixes: https://github.com/nodejs/node/issues/61801
2026-04-27 18:03:19 +02:00
..
es-module.status test: skip tests that cause timeouts on IBM i 2025-08-04 13:35:50 +02:00
test-cjs-esm-warn.js module: unflag --experimental-require-module 2024-11-27 00:44:46 -05:00
test-cjs-legacyMainResolve-permission.js src,lib: stabilize permission model 2025-01-05 13:05:28 -05:00
test-cjs-legacyMainResolve.js esm: do not interpret "main" as a URL 2024-10-04 19:20:13 +02:00
test-cjs-prototype-pollution.js
test-disable-require-module-with-detection.js module: check --experimental-require-module separately from detection 2024-11-27 00:45:12 -05:00
test-dynamic-import-script-lifetime.js module: use symbol in WeakMap to manage host defined options 2023-09-14 15:42:24 +00:00
test-esm-assert-strict.mjs
test-esm-assertionless-json-import.js esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-basic-imports.mjs
test-esm-child-process-fork-main.mjs
test-esm-cjs-builtins.js
test-esm-cjs-exports.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-esm-cjs-load-error-note.mjs module: add dynamic file-specific ESM warnings 2025-04-17 10:51:17 -03:00
test-esm-cjs-main.js
test-esm-cjs-named-error.mjs test: ensure never settling promises are detected 2023-10-23 17:55:50 +00:00
test-esm-custom-exports.mjs
test-esm-cyclic-dynamic-import.mjs
test-esm-data-urls.js esm: use Undici/fetch data: URL parser 2024-09-12 11:06:47 +02:00
test-esm-default-type.mjs
test-esm-detect-ambiguous.mjs module: update tests for combined ambiguous module syntax error 2025-07-24 20:08:27 +02:00
test-esm-dns-promises.mjs
test-esm-double-encoding.mjs
test-esm-dynamic-import-attribute.js esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-dynamic-import-attribute.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-dynamic-import-commonjs.js esm: do not call getSource when format is commonjs 2023-11-29 09:21:54 +00:00
test-esm-dynamic-import-commonjs.mjs esm: do not call getSource when format is commonjs 2023-11-29 09:21:54 +00:00
test-esm-dynamic-import-mutating-fs.js
test-esm-dynamic-import-mutating-fs.mjs
test-esm-dynamic-import.js test: split indirect eval import tests 2025-07-24 20:08:21 +02:00
test-esm-encoded-path-native.js
test-esm-encoded-path.mjs
test-esm-error-cache.js esm: link modules synchronously when no async loader hooks are used 2025-09-20 04:32:39 +00:00
test-esm-example-loader.mjs
test-esm-experimental-warnings.mjs lib,src: drop --experimental-network-imports 2024-08-05 11:15:46 -03:00
test-esm-export-not-found.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-exports-deprecations.mjs
test-esm-exports.mjs test: replace .substr with .slice 2024-06-01 10:54:57 +02:00
test-esm-extension-lookup-deprecation.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-extensionless-esm-and-wasm.mjs test: fix invalid wasm test 2024-10-04 10:20:11 +02:00
test-esm-forbidden-globals.mjs
test-esm-fs-promises.mjs
test-esm-import-assertion-warning.mjs esm: fix inconsistency with importAssertion in resolve hook 2024-11-27 01:37:51 -05:00
test-esm-import-attributes-1.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-import-attributes-2.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-import-attributes-3.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-import-attributes-errors.js esm: link modules synchronously when no async loader hooks are used 2025-09-20 04:32:39 +00:00
test-esm-import-attributes-errors.mjs esm: link modules synchronously when no async loader hooks are used 2025-09-20 04:32:39 +00:00
test-esm-import-attributes-identity.mjs module: link module with a module request record 2025-10-07 16:08:51 +02:00
test-esm-import-attributes-validation.js esm: rename error code related to import attributes 2023-10-18 14:27:55 +00:00
test-esm-import-flag.mjs module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-esm-import-json-named-export.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-import-meta-main-eval.mjs test: skip failing tests when compiled without amaro 2026-02-17 15:12:34 +01:00
test-esm-import-meta-main.mjs esm: implement import.meta.main 2025-07-28 08:46:16 +02:00
test-esm-import-meta-resolve-hooks.mjs test: asserts that import.meta.resolve invokes sync loader hooks 2026-02-24 00:37:12 +01:00
test-esm-import-meta-resolve.mjs esm: fix import.meta.resolve crash 2024-11-27 11:03:35 -05:00
test-esm-import-meta.mjs esm: implement import.meta.main 2025-07-28 08:46:16 +02:00
test-esm-imports-deprecations.mjs
test-esm-imports.mjs test: replace .substr with .slice 2024-06-01 10:54:57 +02:00
test-esm-in-require-cache-2.mjs module: only put directly require-d ESM into require.cache 2026-04-27 18:03:12 +02:00
test-esm-in-require-cache.js module: only put directly require-d ESM into require.cache 2026-04-27 18:03:12 +02:00
test-esm-initialization.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-invalid-data-urls.js
test-esm-invalid-pjson.js test: use unusual chars in the path to ensure our tests are robust 2025-01-31 01:16:46 +01:00
test-esm-json-cache.mjs esm: use import attributes instead of import assertions 2023-10-14 03:52:38 +00:00
test-esm-json.mjs module: link module with a module request record 2025-10-07 16:08:51 +02:00
test-esm-live-binding.mjs
test-esm-loader-cache-clearing.js
test-esm-loader-chaining.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-loader-custom-condition.mjs
test-esm-loader-default-resolver.mjs esm: identify parent importing a url with invalid host 2023-09-23 05:41:26 +00:00
test-esm-loader-dependency.mjs
test-esm-loader-entry-url.mjs test: skip failing tests when compiled without amaro 2026-02-17 15:12:34 +01:00
test-esm-loader-event-loop.mjs
test-esm-loader-hooks.mjs src,loader,permission: throw on InternalWorker use 2025-01-20 10:47:28 -03:00
test-esm-loader-http-imports.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-loader-invalid-format.mjs
test-esm-loader-invalid-url.mjs
test-esm-loader-mock.mjs Revert "module: have a single hooks thread for all workers" 2024-06-03 08:48:35 +02:00
test-esm-loader-modulemap.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-esm-loader-not-found.mjs
test-esm-loader-programmatically.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-loader-resolve-type.mjs test: use tmpdir.refresh() in test-esm-loader-resolve-type.mjs 2023-12-20 18:17:31 +00:00
test-esm-loader-search.js
test-esm-loader-spawn-promisified.mjs module: prevent main thread exiting before esm worker ends 2025-01-05 13:05:26 -05:00
test-esm-loader-stringify-text.mjs
test-esm-loader-thenable.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-loader-with-source.mjs esm: do not call getSource when format is commonjs 2023-11-29 09:21:54 +00:00
test-esm-loader-with-syntax-error.mjs lib: update inspect output format for subclasses 2025-10-07 17:29:40 +02:00
test-esm-loader.mjs esm: fix hook name in error message 2023-12-05 19:54:01 +01:00
test-esm-long-path-win.js module: add dynamic file-specific ESM warnings 2025-04-17 10:51:17 -03:00
test-esm-main-lookup.mjs esm: add a fallback when importer in not a file 2024-11-27 02:25:38 -05:00
test-esm-module-not-found-commonjs-hint.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-named-exports.mjs Revert "module: have a single hooks thread for all workers" 2024-06-03 08:48:35 +02:00
test-esm-namespace.mjs
test-esm-no-addons.mjs test: change jenkins reporter 2025-04-16 03:26:28 -03:00
test-esm-non-js.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-nowarn-exports.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-path-posix.mjs
test-esm-path-win32.mjs
test-esm-pkgname.mjs test: refactor some esm tests 2024-11-27 11:03:31 -05:00
test-esm-preserve-symlinks-main.js test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-preserve-symlinks-not-found-plain.mjs
test-esm-preserve-symlinks-not-found.mjs
test-esm-preserve-symlinks.js
test-esm-process.mjs
test-esm-prototype-pollution.mjs
test-esm-recursive-cjs-dependencies.mjs
test-esm-repl-imports.js test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-repl.js
test-esm-require-cache.mjs
test-esm-resolve-type.mjs test: skip failing tests when compiled without amaro 2026-02-17 15:12:34 +01:00
test-esm-scope-node-modules.mjs
test-esm-shared-loader-dep.mjs
test-esm-shebang.mjs
test-esm-snapshot.mjs
test-esm-source-map.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-symlink-main.js
test-esm-symlink-type.js
test-esm-symlink.js
test-esm-syntax-error.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-throw-undefined.mjs
test-esm-tla-syntax-errors-not-recognized-as-tla-error.mjs module: correctly detect top-level await in ambiguous contexts 2025-09-20 03:33:27 +00:00
test-esm-tla-unfinished.mjs src: fix process exit listeners not receiving unsettled tla codes 2025-04-17 10:51:29 -03:00
test-esm-tla.mjs
test-esm-type-field-errors-2.js module: unflag --experimental-require-module 2024-11-27 00:44:46 -05:00
test-esm-type-field-errors.js module: unflag --experimental-require-module 2024-11-27 00:44:46 -05:00
test-esm-type-field.mjs esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
test-esm-type-flag-cli-entry.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-type-flag-errors.mjs module: handle null source from async loader hooks in sync hooks 2026-04-27 18:03:19 +02:00
test-esm-type-flag-loose-files.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-type-flag-package-scopes.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-type-flag-string-input.mjs test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-type-main.mjs
test-esm-undefined-cjs-global-like-variables.js
test-esm-unknown-extension.js test: do not set concurrency on parallelized runs 2024-03-23 21:11:28 +00:00
test-esm-url-extname.js esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
test-esm-util-types.mjs
test-esm-virtual-json.mjs Revert "module: have a single hooks thread for all workers" 2024-06-03 08:48:35 +02:00
test-esm-wasm.mjs esm: unflag --experimental-wasm-modules 2025-08-27 00:55:20 +02:00
test-esm-windows.js
test-import-module-conditional-exports-module.mjs module: implement the "module-sync" exports condition 2024-10-04 10:20:25 +02:00
test-import-module-retry-require-errored.js module: throw error when re-runing errored module jobs 2025-08-20 16:23:54 +02:00
test-import-preload-require-cycle.js module: allow cycles in require() in the CJS handling in ESM loader 2025-07-24 20:08:21 +02:00
test-loaders-hidden-from-users.js
test-loaders-unknown-builtin-module.mjs
test-loaders-workers-spawned.mjs test: make test-loaders-workers-spawned less flaky 2024-10-09 22:59:04 +02:00
test-require-as-esm-interop.mjs module: support 'module.exports' interop export in require(esm) 2024-11-27 00:44:51 -05:00
test-require-esm-from-imported-cjs.js esm: populate separate cache for require(esm) in imported CJS 2026-04-27 18:03:09 +02:00
test-require-module-cached-tla.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-require-module-conditional-exports-module.js module: implement the "module-sync" exports condition 2024-10-04 10:20:25 +02:00
test-require-module-conditional-exports.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-require-module-cycle-cjs-esm-esm.js module: cache synchronous module jobs before linking 2024-05-11 18:55:48 +02:00
test-require-module-cycle-esm-cjs-esm-esm.js module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
test-require-module-cycle-esm-cjs-esm.js module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
test-require-module-cycle-esm-esm-cjs-esm-esm.js module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
test-require-module-cycle-esm-esm-cjs-esm.js module: disallow CJS <-> ESM edges in a cycle from require(esm) 2024-04-08 14:45:55 +00:00
test-require-module-default-extension.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-defined-esmodule.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-detect-entry-point-aou.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-require-module-detect-entry-point.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-require-module-dont-detect-cjs.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-require-module-dynamic-import-1.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-dynamic-import-2.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-dynamic-import-3.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-dynamic-import-4.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-error-catching.js module: clarify cjs global-like error on ModuleJobSync 2025-06-10 14:52:16 +02:00
test-require-module-errors.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-require-module-feature-detect.js module: unflag --experimental-require-module 2024-11-27 00:44:46 -05:00
test-require-module-implicit.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-require-module-instantiated.mjs module: handle instantiated async module jobs in require(esm) 2025-06-10 16:38:57 +02:00
test-require-module-preload.js module: only emit require(esm) warning under --trace-require-module 2025-01-05 13:05:26 -05:00
test-require-module-retry-import-errored-2.js module: throw error when re-runing errored module jobs 2025-08-20 16:23:54 +02:00
test-require-module-retry-import-errored.js module: allow ESM that failed to be required to be re-imported 2024-11-27 00:45:27 -05:00
test-require-module-retry-import-evaluating.js module: allow ESM that failed to be required to be re-imported 2024-11-27 00:45:27 -05:00
test-require-module-synchronous-rejection-handling.js module: mark evaluation rejection in require(esm) as handled 2025-01-05 12:57:35 -05:00
test-require-module-tla-execution.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-tla-nested.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-tla-print-execution.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-tla-rejected.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-tla-resolved.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-tla-retry-import-2.js tools,test: enforce best practices to detect never settling promises 2025-08-04 13:29:04 +02:00
test-require-module-tla-retry-import.js tools,test: enforce best practices to detect never settling promises 2025-08-04 13:29:04 +02:00
test-require-module-tla-retry-require.js module: fix error thrown from require(esm) hitting TLA repeatedly 2024-11-27 11:03:26 -05:00
test-require-module-tla-unresolved.js module: improve error message from asynchronicity in require(esm) 2025-04-17 10:51:02 -03:00
test-require-module-transpiled.js module: add __esModule to require()'d ESM 2024-07-16 12:01:18 +02:00
test-require-module-twice.js module: support require()ing synchronous ESM graphs 2024-03-18 18:10:06 +08:00
test-require-module-warning.js module: only emit require(esm) warning under --trace-require-module 2025-01-05 13:05:26 -05:00
test-require-module-with-detection.js module: unflag detect-module 2024-08-19 10:01:38 -03:00
test-require-module.js module: only emit require(esm) warning under --trace-require-module 2025-01-05 13:05:26 -05:00
test-require-node-modules-warning.js module: only emit require(esm) warning under --trace-require-module 2025-01-05 13:05:26 -05:00
test-typescript-commonjs.mjs module: use sync cjs when importing cts 2026-04-27 18:03:16 +02:00
test-typescript-eval.mjs deps: update amaro to 0.5.1 2025-07-15 19:03:11 -03:00
test-typescript-module.mjs module: use sync cjs when importing cts 2026-04-27 18:03:16 +02:00
test-typescript-transform.mjs test: module syntax should throw 2025-04-17 10:51:37 -03:00
test-typescript.mjs lib: fix TypeScript support check in jitless mode 2026-02-24 08:38:57 +01:00
test-vm-compile-function-leak.js test: use checkIfCollectable in vm leak tests 2023-09-18 23:00:53 +02:00
test-vm-compile-function-lineoffset.js lib: fix compileFunction throws range error for negative numbers 2023-10-06 14:33:46 +00:00
test-vm-contextified-script-leak.js test: deflake test-vm-contextified-script-leak 2023-09-23 03:46:22 +00:00
test-vm-main-context-default-loader-eval.js tools,test: enforce best practices to detect never settling promises 2025-08-04 13:29:04 +02:00
test-vm-main-context-default-loader.js tools,test: enforce best practices to detect never settling promises 2025-08-04 13:29:04 +02:00
test-vm-source-text-module-leak.js v8: implement v8.queryObjects() for memory leak regression testing 2024-03-02 22:11:30 +00:00
test-vm-synthetic-module-leak.js test: use checkIfCollectable in vm leak tests 2023-09-18 23:00:53 +02:00
test-wasm-memory-out-of-bound.js esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
test-wasm-simple.js esm: --experimental-default-type flag to flip module defaults 2023-09-29 06:18:44 +00:00
test-wasm-web-api.js fs: add autoClose option to FileHandle readableWebStream 2025-06-10 18:20:32 +02:00
testcfg.py