Skip to content

Commit 844fe45

Browse files
GeoffreyBoothaduh95
authored andcommitted
Review notes
1 parent a12d520 commit 844fe45

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

test/es-module/test-esm-loader-mock.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --no-warnings --import ./test/fixtures/es-module-loaders/mock.mjs
1+
// Flags: --import ./test/fixtures/es-module-loaders/mock.mjs
22
import assert from 'node:assert/strict';
33
import { mock } from '../fixtures/es-module-loaders/mock.mjs';
44

test/fixtures/es-module-loaders/mock-loader.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ let currentMockVersion = 0;
3333
// assert(namespace1 === namespace2);
3434
// ```
3535

36-
37-
export async function initialize({ port }) {
38-
port.on('message', ({ mockVersion, resolved, exports }) => {
36+
/** @type {string} */
37+
let mainImportURL;
38+
export async function initialize(data) {
39+
mainImportURL = data.mainImportURL;
40+
data.port.on('message', ({ mockVersion, resolved, exports }) => {
3941
currentMockVersion = mockVersion;
4042
mockedModuleExports.set(resolved, exports);
4143
});
@@ -75,7 +77,6 @@ export async function load(url, context, defaultLoad) {
7577
return defaultLoad(url, context);
7678
}
7779

78-
const mainImportURL = new URL('./mock.mjs', import.meta.url);
7980
/**
8081
* Generate the source code for a mocked module.
8182
* @param {string} encodedTargetURL the module being mocked
@@ -86,7 +87,7 @@ function generateModule(encodedTargetURL) {
8687
decodeURIComponent(encodedTargetURL)
8788
);
8889
let body = [
89-
`import { mockedModules } from '${mainImportURL}';`,
90+
`import { mockedModules } from ${JSON.stringify(mainImportURL)};`,
9091
'export {};',
9192
'let mapping = {__proto__: null};'
9293
];

test/fixtures/es-module-loaders/mock.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { MessageChannel } from 'node:worker_threads';
66
const { port1, port2 } = new MessageChannel();
77

88
register(fixtures.fileURL('es-module-loaders/mock-loader.mjs'), {
9-
data: { port: port2 },
9+
data: {
10+
port: port2,
11+
mainImportURL: import.meta.url,
12+
},
1013
transferList: [port2],
1114
});
1215

0 commit comments

Comments
 (0)