2024-05-08 02:20:48 +00:00
|
|
|
import { skipIfWorker } from '../common/index.mjs';
|
2023-09-05 01:13:40 +00:00
|
|
|
import assert from 'node:assert/strict';
|
|
|
|
import { mock } from '../fixtures/es-module-loaders/mock.mjs';
|
2024-05-08 02:20:48 +00:00
|
|
|
// Importing mock.mjs above will call `register` to modify the loaders chain.
|
|
|
|
// Modifying the loader chain is not supported currently when running from a worker thread.
|
|
|
|
// Relevant PR: https://github.com/nodejs/node/pull/52706
|
|
|
|
// See comment: https://github.com/nodejs/node/pull/52706/files#r1585144580
|
|
|
|
skipIfWorker();
|
2023-07-17 15:26:15 +00:00
|
|
|
|
|
|
|
mock('node:events', {
|
|
|
|
EventEmitter: 'This is mocked!'
|
|
|
|
});
|
|
|
|
|
|
|
|
// This resolves to node:events
|
|
|
|
// It is intercepted by mock-loader and doesn't return the normal value
|
|
|
|
assert.deepStrictEqual(await import('events'), Object.defineProperty({
|
|
|
|
__proto__: null,
|
|
|
|
EventEmitter: 'This is mocked!'
|
|
|
|
}, Symbol.toStringTag, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 'Module'
|
|
|
|
}));
|
|
|
|
|
|
|
|
const mutator = mock('node:events', {
|
|
|
|
EventEmitter: 'This is mocked v2!'
|
|
|
|
});
|
|
|
|
|
|
|
|
// It is intercepted by mock-loader and doesn't return the normal value.
|
|
|
|
// This is resolved separately from the import above since the specifiers
|
|
|
|
// are different.
|
|
|
|
const mockedV2 = await import('node:events');
|
|
|
|
assert.deepStrictEqual(mockedV2, Object.defineProperty({
|
|
|
|
__proto__: null,
|
|
|
|
EventEmitter: 'This is mocked v2!'
|
|
|
|
}, Symbol.toStringTag, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 'Module'
|
|
|
|
}));
|
|
|
|
|
|
|
|
mutator.EventEmitter = 'This is mocked v3!';
|
|
|
|
assert.deepStrictEqual(mockedV2, Object.defineProperty({
|
|
|
|
__proto__: null,
|
|
|
|
EventEmitter: 'This is mocked v3!'
|
|
|
|
}, Symbol.toStringTag, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 'Module'
|
|
|
|
}));
|