mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
PR-URL: https://github.com/nodejs/node/pull/60125 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
35 lines
866 B
JavaScript
35 lines
866 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { registerHooks } = require('module');
|
|
|
|
// Test that multiple loaders works together.
|
|
const hook1 = registerHooks({
|
|
load: common.mustCall((url, context, nextLoad) => {
|
|
const result = nextLoad(url, context);
|
|
assert.strictEqual(result.source, '');
|
|
return {
|
|
source: 'exports.hello = "world"',
|
|
format: 'commonjs',
|
|
};
|
|
}),
|
|
});
|
|
|
|
const hook2 = registerHooks({
|
|
load: common.mustCall((url, context, nextLoad) => {
|
|
const result = nextLoad(url, context);
|
|
assert.strictEqual(result.source, 'exports.hello = "world"');
|
|
return {
|
|
source: 'export const hello = "world"',
|
|
format: 'module',
|
|
};
|
|
}),
|
|
});
|
|
|
|
const mod = require('../fixtures/empty.js');
|
|
assert.strictEqual(mod.hello, 'world');
|
|
|
|
hook1.deregister();
|
|
hook2.deregister();
|