Skip to content

Commit

Permalink
code review notes
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoffreyBooth committed Feb 15, 2023
1 parent 3f5f827 commit e54cd4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 25 deletions.
12 changes: 4 additions & 8 deletions test/es-module/test-esm-loader-event-loop.mjs
@@ -1,16 +1,12 @@
// Flags: --experimental-loader ./test/fixtures/es-module-loaders/hooks-custom.mjs
import { mustCall } from '../common/index.mjs';
import assert from 'assert';

const done = mustCall(() => { assert.ok(true); });
const done = mustCall();


// Test that the process doesn't exit because of a caught exception thrown as part of dynamic import().
await import('nonexistent/file.mjs').catch(() => {});
await import('nonexistent/file.mjs').catch(() => {});
await import('nonexistent/file.mjs').catch(() => {});
await import('nonexistent/file.mjs').catch(() => {});
await import('nonexistent/file.mjs').catch(() => {});
await import('nonexistent/file.mjs').catch(() => {});
for (let i = 0; i < 10; i++) {
await import('nonexistent/file.mjs').catch(() => {});
}

done();
42 changes: 29 additions & 13 deletions test/es-module/test-esm-loader-spawn-promisified.mjs
Expand Up @@ -12,7 +12,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'nonexistent/file.mjs\'',
'import "nonexistent/file.mjs"',
]);

assert.strictEqual(code, 1);
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/badReturnVal.mjs\'',
'import "esmHook/badReturnVal.mjs"',
]);

assert.strictEqual(code, 1);
Expand All @@ -60,7 +60,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/format.false\'',
'import "esmHook/format.false"',
]);

assert.strictEqual(code, 1);
Expand All @@ -75,7 +75,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/format.true\'',
'import "esmHook/format.true"',
]);

assert.strictEqual(code, 1);
Expand All @@ -91,7 +91,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/badReturnFormatVal.mjs\'',
'import "esmHook/badReturnFormatVal.mjs"',
]);

assert.strictEqual(code, 1);
Expand All @@ -107,7 +107,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/unsupportedReturnFormatVal.mjs\'',
'import "esmHook/unsupportedReturnFormatVal.mjs"',
]);

assert.strictEqual(code, 1);
Expand All @@ -123,7 +123,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'),
'--input-type=module',
'--eval',
'import \'esmHook/badReturnSourceVal.mjs\'',
'import "esmHook/badReturnSourceVal.mjs"',
]);

assert.strictEqual(code, 1);
Expand All @@ -140,7 +140,7 @@ describe('Loader hooks throwing errors', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
Promise.allSettled([
await Promise.allSettled([
import('nonexistent/file.mjs'),
import('${fixtures.fileURL('/es-modules/file.unknown')}'),
import('esmHook/badReturnVal.mjs'),
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}')
await import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}')
.then((parsedModule) => {
assert.strictEqual(typeof parsedModule, 'object');
assert.strictEqual(parsedModule.namedExport, 'named-export');
Expand All @@ -191,7 +191,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
import('${fixtures.fileURL('/es-modules/file.ext')}')
await import('${fixtures.fileURL('/es-modules/file.ext')}')
.then((parsedModule) => {
assert.strictEqual(typeof parsedModule, 'object');
const { default: defaultExport } = parsedModule;
Expand All @@ -215,7 +215,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
import('esmHook/preknownFormat.pre')
await import('esmHook/preknownFormat.pre')
.then((parsedModule) => {
assert.strictEqual(typeof parsedModule, 'object');
assert.strictEqual(parsedModule.default, 'hello world');
Expand All @@ -236,7 +236,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
import('esmHook/virtual.mjs')
await import('esmHook/virtual.mjs')
.then((parsedModule) => {
assert.strictEqual(typeof parsedModule, 'object');
assert.strictEqual(typeof parsedModule.default, 'undefined');
Expand All @@ -258,7 +258,7 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
'--input-type=module',
'--eval',
`import assert from 'node:assert';
import('${fixtures.fileURL('/es-modules/stateful.mjs')}')
await import('${fixtures.fileURL('/es-modules/stateful.mjs')}')
.then(({ default: count }) => {
assert.strictEqual(count(), 1);
});`,
Expand All @@ -269,4 +269,20 @@ describe('Loader hooks parsing modules', { concurrency: true }, () => {
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
});

it('ensures that user loaders are not bound to the internal loader', async () => {
const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [
'--no-warnings',
'--experimental-loader',
fixtures.fileURL('/es-module-loaders/loader-this-value-inside-hook-functions.mjs'),
'--input-type=module',
'--eval',
';', // Actual test is inside the loader module.
]);

assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
assert.strictEqual(stdout, '');
assert.strictEqual(stderr, '');
});
});

This file was deleted.

0 comments on commit e54cd4e

Please sign in to comment.