node/test/module-hooks
Joyee Cheung 96f19a16d0
module: fix sync hook short-circuit in require() in imported CJS
- For imported CJS, if it's not customized by asynchronous hooks,
  make sure it won't use the quirky re-invented require in all
  cases.
- When the imported CJS module is customized by synchronous hooks,
  in the synthetic module evalutation step, avoid calling the
  respective default step again.
- Make the branching of loadCJSModuleWithModuleLoad() and
  loadCJSModuleWithSpecialRequire() more explicit, and fold
  the tentative fs read in the 'commonjs' translator into the
  share createCJSModuleWrap() helper instead of checking it
  twice in the same path.

Signed-off-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/62920
Fixes: https://github.com/nodejs/node/issues/63060
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
2026-05-19 14:08:17 +02:00
..
module-hooks.status
test-async-loader-hooks-called-with-expected-args.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-called-with-register.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-globalpreload-no-warning-with-initialize.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-globalpreload-warning.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-in-sequence.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-invoke.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-never-settling.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-process-exit.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-rejecting.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-initialize-throw-null.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-mixed-opt-in.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-import-meta-resolve.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-load-cjs.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-load-esm-no-warning.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-load-esm-with-warning.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-race-cjs.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-race-esm.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-resolve-cjs.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-resolve-esm-no-warning.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-never-settling-resolve-esm-with-warning.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-no-leak-internals.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-process-exit-async.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-process-exit-sync.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-process-exit-top-level.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-register-with-cjs.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-register-with-import.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-register-with-ports.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-register-with-require.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-register-with-url-parenturl.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-remove-beforeexit-listener.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-require-resolve-default.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-require-resolve-opt-in.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-source-maps-cjs.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-bigint.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-boolean.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-empty-object.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-error.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-function.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-null.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-number.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-object.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-string.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-symbol.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-throw-undefined.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-use-hooks-require-esm.mjs module: runtime-deprecate module.register() 2026-04-14 10:57:14 +01:00
test-async-loader-hooks-with-worker-permission-allowed.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-with-worker-permission-restricted.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-async-loader-hooks-without-worker-permission.mjs test: split test-esm-loader-hooks 2026-01-16 14:30:12 +00:00
test-module-hooks-builtin-require.js lib,src,test: fix tests without SQLite 2025-12-11 23:04:24 +01:00
test-module-hooks-create-require-with-url.mjs module: preserve URL in the parent created by createRequire() 2025-12-13 07:36:20 +00:00
test-module-hooks-custom-conditions-cjs.js test: ensure assertions are reached on more tests 2025-11-11 09:56:18 +00:00
test-module-hooks-custom-conditions-special-values.js
test-module-hooks-custom-conditions.mjs test: ensure assertions are reached on more tests 2025-11-11 09:56:18 +00:00
test-module-hooks-import-wasm.mjs tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-async-and-sync.js module: handle null source from async loader hooks in sync hooks 2025-10-14 16:28:22 +00:00
test-module-hooks-load-buffers.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-builtin-import.mjs
test-module-hooks-load-builtin-override-commonjs.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-load-builtin-override-json.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-load-builtin-override-module.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-load-builtin-require.js lib,src,test: fix tests without SQLite 2025-12-11 23:04:24 +01:00
test-module-hooks-load-chained.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-context-merged-esm.mjs
test-module-hooks-load-context-merged.js
test-module-hooks-load-context-optional-esm.mjs
test-module-hooks-load-context-optional.js
test-module-hooks-load-detection.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-load-esm-mock.js
test-module-hooks-load-esm.js
test-module-hooks-load-import-cjs-custom-source.js module: fix sync hook short-circuit in require() in imported CJS 2026-05-19 14:08:17 +02:00
test-module-hooks-load-import-cjs.js module: do not invoke resolve hooks twice for imported cjs 2026-02-02 23:04:23 +00:00
test-module-hooks-load-invalid.js
test-module-hooks-load-mock.js
test-module-hooks-load-short-circuit-required-middle.js
test-module-hooks-load-short-circuit-required-start.js
test-module-hooks-load-short-circuit.js
test-module-hooks-load-url-change-import.mjs test: forbid use of named imports for fixtures 2026-01-01 23:48:26 +00:00
test-module-hooks-load-url-change-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-preload.js module: remove --experimental-transform-types 2026-02-27 16:32:43 +00:00
test-module-hooks-require-esm.js esm: use sync loading/resolving on non-loader-hook thread 2025-10-31 20:45:10 +00:00
test-module-hooks-require-wasm.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-builtin-builtin-import.mjs
test-module-hooks-resolve-builtin-builtin-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-builtin-on-disk-import.mjs test: forbid use of named imports for fixtures 2026-01-01 23:48:26 +00:00
test-module-hooks-resolve-builtin-on-disk-require-with-prefix.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-resolve-builtin-on-disk-require.js tools: add lint rule to ensure assertions are reached 2025-10-07 12:40:05 +00:00
test-module-hooks-resolve-context-merged-esm.mjs
test-module-hooks-resolve-context-merged.js
test-module-hooks-resolve-context-optional-esm.mjs
test-module-hooks-resolve-context-optional.js
test-module-hooks-resolve-import-cjs.js module: do not invoke resolve hooks twice for imported cjs 2026-02-02 23:04:23 +00:00
test-module-hooks-resolve-invalid.js
test-module-hooks-resolve-load-builtin-override-both-prefix.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-resolve-load-builtin-override-both.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-resolve-load-builtin-redirect-prefix.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-resolve-load-builtin-redirect.js module: fix sync resolve hooks for require with node: prefixes 2025-12-22 14:35:45 +00:00
test-module-hooks-resolve-load-import-inline-typescript-override.mjs module: remove --experimental-transform-types 2026-02-27 16:32:43 +00:00
test-module-hooks-resolve-load-import-inline-typescript.mjs module: remove --experimental-transform-types 2026-02-27 16:32:43 +00:00
test-module-hooks-resolve-load-require-inline-typescript-override.js module: remove --experimental-transform-types 2026-02-27 16:32:43 +00:00
test-module-hooks-resolve-load-require-inline-typescript.js module: remove --experimental-transform-types 2026-02-27 16:32:43 +00:00
test-module-hooks-resolve-require-resolve-builtin.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-consistency.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-create-require.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-fallthrough.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-imported-cjs.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-loaded-with-source.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-paths.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-require-resolve-redirect.js module: run require.resolve through module.registerHooks() 2026-03-02 18:28:25 +00:00
test-module-hooks-resolve-short-circuit-required-middle.js
test-module-hooks-resolve-short-circuit-required-start.js
test-module-hooks-resolve-short-circuit.js
testcfg.py