Skip to content

Commit b749323

Browse files
aduh95danielleadams
authored andcommitted
esm: increase test coverage of edge cases
PR-URL: #47033 Backport-PR-URL: #47433 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Jacob Smith <[email protected]>
1 parent ddbf518 commit b749323

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

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

+30
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ describe('Loader hooks', { concurrency: true }, () => {
6767
assert.strictEqual(code, 0);
6868
assert.strictEqual(signal, null);
6969
});
70+
71+
it('import.meta.resolve of a never-settling resolve', async () => {
72+
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
73+
'--no-warnings',
74+
'--experimental-import-meta-resolve',
75+
'--experimental-loader',
76+
fixtures.fileURL('es-module-loaders/never-settling-resolve-step/loader.mjs'),
77+
fixtures.path('es-module-loaders/never-settling-resolve-step/import.meta.never-resolve.mjs'),
78+
]);
79+
80+
assert.strictEqual(stderr, '');
81+
assert.match(stdout, /^should be output\r?\n$/);
82+
assert.strictEqual(code, 13);
83+
assert.strictEqual(signal, null);
84+
});
7085
});
7186

7287
describe('should handle never-settling hooks in CJS files', { concurrency: true }, () => {
@@ -113,4 +128,19 @@ describe('Loader hooks', { concurrency: true }, () => {
113128
assert.strictEqual(signal, null);
114129
});
115130
});
131+
132+
it('should not leak internals or expose import.meta.resolve', async () => {
133+
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
134+
'--no-warnings',
135+
'--experimental-import-meta-resolve',
136+
'--experimental-loader',
137+
fixtures.fileURL('es-module-loaders/loader-edge-cases.mjs'),
138+
fixtures.path('empty.js'),
139+
]);
140+
141+
assert.strictEqual(stderr, '');
142+
assert.strictEqual(stdout, '');
143+
assert.strictEqual(code, 0);
144+
assert.strictEqual(signal, null);
145+
});
116146
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { strictEqual } from "node:assert";
2+
import { isMainThread, workerData, parentPort } from "node:worker_threads";
3+
4+
// TODO(aduh95): switch this to `false` when loader hooks are run on a separate thread.
5+
strictEqual(isMainThread, true);
6+
7+
// We want to make sure that internals are not leaked on the public module:
8+
strictEqual(workerData, null);
9+
strictEqual(parentPort, null);
10+
11+
// TODO(aduh95): switch to `"undefined"` when loader hooks are run on a separate thread.
12+
// We don't want `import.meta.resolve` being available from loaders
13+
// as the sync implementation is not compatible with calling async
14+
// functions on the same thread.
15+
strictEqual(typeof import.meta.resolve, 'function');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
console.log('should be output');
2+
3+
await import.meta.resolve('never-settle-resolve');
4+
5+
console.log('should not be output');

0 commit comments

Comments
 (0)