mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00

Some checks are pending
Coverage Linux (without intl) / coverage-linux-without-intl (push) Waiting to run
Coverage Linux / coverage-linux (push) Waiting to run
Coverage Windows / coverage-windows (push) Waiting to run
Test and upload documentation to artifacts / build-docs (push) Waiting to run
Linters / lint-addon-docs (push) Waiting to run
Linters / lint-cpp (push) Waiting to run
Linters / format-cpp (push) Waiting to run
Linters / lint-js-and-md (push) Waiting to run
Linters / lint-py (push) Waiting to run
Linters / lint-yaml (push) Waiting to run
Linters / lint-sh (push) Waiting to run
Linters / lint-codeowners (push) Waiting to run
Linters / lint-pr-url (push) Waiting to run
Linters / lint-readme (push) Waiting to run
Notify on Push / Notify on Force Push on `main` (push) Waiting to run
Notify on Push / Notify on Push on `main` that lacks metadata (push) Waiting to run
Scorecard supply-chain security / Scorecard analysis (push) Waiting to run
This aligns the behavior of synchronous hooks with asynchronous hooks by allowing omission of the context parameter in the invocation of next hooks. The contexts are merged along the chain. PR-URL: https://github.com/nodejs/node/pull/57056 Fixes: https://github.com/nodejs/node/issues/57030 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
32 lines
967 B
JavaScript
32 lines
967 B
JavaScript
// Test that the context parameter will be merged in multiple load hooks.
|
|
|
|
import * as common from '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import { registerHooks } from 'node:module';
|
|
|
|
const hook1 = registerHooks({
|
|
load: common.mustCall(function(url, context, nextLoad) {
|
|
assert.strictEqual(context.testProp, 'custom'); // It should be merged from hook 2 and 3.
|
|
return nextLoad(url, context);
|
|
}, 1),
|
|
});
|
|
|
|
const hook2 = registerHooks({
|
|
load: common.mustCall(function(url, context, nextLoad) {
|
|
assert.strictEqual(context.testProp, 'custom'); // It should be merged from hook 3.
|
|
return nextLoad(url); // Omit the context.
|
|
}, 1),
|
|
});
|
|
|
|
const hook3 = registerHooks({
|
|
load: common.mustCall(function(url, context, nextLoad) {
|
|
return nextLoad(url, { testProp: 'custom' }); // Add a custom property
|
|
}, 1),
|
|
});
|
|
|
|
await import('../fixtures/es-modules/message.mjs');
|
|
|
|
hook3.deregister();
|
|
hook2.deregister();
|
|
hook1.deregister();
|