mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
esm: increase test coverage of edge cases
PR-URL: https://github.com/nodejs/node/pull/47033 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Jacob Smith <jacob@frende.me>
This commit is contained in:
parent
accfe8e79a
commit
841f6b3abf
|
|
@ -67,6 +67,21 @@ describe('Loader hooks', { concurrency: true }, () => {
|
|||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
});
|
||||
|
||||
it('import.meta.resolve of a never-settling resolve', async () => {
|
||||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
|
||||
'--no-warnings',
|
||||
'--experimental-import-meta-resolve',
|
||||
'--experimental-loader',
|
||||
fixtures.fileURL('es-module-loaders/never-settling-resolve-step/loader.mjs'),
|
||||
fixtures.path('es-module-loaders/never-settling-resolve-step/import.meta.never-resolve.mjs'),
|
||||
]);
|
||||
|
||||
assert.strictEqual(stderr, '');
|
||||
assert.match(stdout, /^should be output\r?\n$/);
|
||||
assert.strictEqual(code, 13);
|
||||
assert.strictEqual(signal, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('should handle never-settling hooks in CJS files', { concurrency: true }, () => {
|
||||
|
|
@ -165,4 +180,19 @@ describe('Loader hooks', { concurrency: true }, () => {
|
|||
assert.strictEqual(code, 1);
|
||||
assert.strictEqual(signal, null);
|
||||
});
|
||||
|
||||
it('should not leak internals or expose import.meta.resolve', async () => {
|
||||
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
|
||||
'--no-warnings',
|
||||
'--experimental-import-meta-resolve',
|
||||
'--experimental-loader',
|
||||
fixtures.fileURL('es-module-loaders/loader-edge-cases.mjs'),
|
||||
fixtures.path('empty.js'),
|
||||
]);
|
||||
|
||||
assert.strictEqual(stderr, '');
|
||||
assert.strictEqual(stdout, '');
|
||||
assert.strictEqual(code, 0);
|
||||
assert.strictEqual(signal, null);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
15
test/fixtures/es-module-loaders/loader-edge-cases.mjs
vendored
Normal file
15
test/fixtures/es-module-loaders/loader-edge-cases.mjs
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { strictEqual } from "node:assert";
|
||||
import { isMainThread, workerData, parentPort } from "node:worker_threads";
|
||||
|
||||
// TODO(aduh95): switch this to `false` when loader hooks are run on a separate thread.
|
||||
strictEqual(isMainThread, true);
|
||||
|
||||
// We want to make sure that internals are not leaked on the public module:
|
||||
strictEqual(workerData, null);
|
||||
strictEqual(parentPort, null);
|
||||
|
||||
// TODO(aduh95): switch to `"undefined"` when loader hooks are run on a separate thread.
|
||||
// We don't want `import.meta.resolve` being available from loaders
|
||||
// as the sync implementation is not compatible with calling async
|
||||
// functions on the same thread.
|
||||
strictEqual(typeof import.meta.resolve, 'function');
|
||||
5
test/fixtures/es-module-loaders/never-settling-resolve-step/import.meta.never-resolve.mjs
vendored
Normal file
5
test/fixtures/es-module-loaders/never-settling-resolve-step/import.meta.never-resolve.mjs
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
console.log('should be output');
|
||||
|
||||
await import.meta.resolve('never-settle-resolve');
|
||||
|
||||
console.log('should not be output');
|
||||
Loading…
Reference in New Issue
Block a user