From 5d7a2b35a31ce2d0b5bc09a398f97413e7be3348 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Mon, 13 Feb 2023 10:00:51 +0100 Subject: [PATCH] remove unrelated added tests --- test/es-module/test-esm-loader-event-loop.mjs | 16 -- .../test-esm-loader-spawn-promisified.mjs | 272 ------------------ .../test-loaders-hidden-from-users.js | 27 -- ...aders-this-value-inside-hook-functions.mjs | 4 - .../test-loaders-unknown-builtin-module.mjs | 12 - 5 files changed, 331 deletions(-) delete mode 100644 test/es-module/test-esm-loader-event-loop.mjs delete mode 100644 test/es-module/test-esm-loader-spawn-promisified.mjs delete mode 100644 test/es-module/test-loaders-hidden-from-users.js delete mode 100644 test/es-module/test-loaders-this-value-inside-hook-functions.mjs delete mode 100644 test/es-module/test-loaders-unknown-builtin-module.mjs diff --git a/test/es-module/test-esm-loader-event-loop.mjs b/test/es-module/test-esm-loader-event-loop.mjs deleted file mode 100644 index c6a071fe25feed..00000000000000 --- a/test/es-module/test-esm-loader-event-loop.mjs +++ /dev/null @@ -1,16 +0,0 @@ -// 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); }); - - -// 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(() => {}); - -done(); diff --git a/test/es-module/test-esm-loader-spawn-promisified.mjs b/test/es-module/test-esm-loader-spawn-promisified.mjs deleted file mode 100644 index c5953128cc6607..00000000000000 --- a/test/es-module/test-esm-loader-spawn-promisified.mjs +++ /dev/null @@ -1,272 +0,0 @@ -import { spawnPromisified } from '../common/index.mjs'; -import * as fixtures from '../common/fixtures.mjs'; -import assert from 'node:assert'; -import { execPath } from 'node:process'; -import { describe, it } from 'node:test'; - -describe('Loader hooks throwing errors', { concurrency: true }, () => { - it('throws on nonexistent modules', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'nonexistent/file.mjs\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_MODULE_NOT_FOUND/); - }); - - it('throws on unknown extensions', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import '${fixtures.fileURL('/es-modules/file.unknown')}'`, - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_UNKNOWN_FILE_EXTENSION/); - }); - - it('throws on invalid return values', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/badReturnVal.mjs\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_INVALID_RETURN_VALUE/); - }); - - it('throws on boolean false', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/format.false\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_INVALID_RETURN_PROPERTY_VALUE/); - }); - it('throws on boolean true', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/format.true\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_INVALID_RETURN_PROPERTY_VALUE/); - }); - - it('throws on invalid returned object', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/badReturnFormatVal.mjs\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_INVALID_RETURN_PROPERTY_VALUE/); - }); - - it('throws on unsupported format', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/unsupportedReturnFormatVal.mjs\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_UNKNOWN_MODULE_FORMAT/); - }); - - it('throws on invalid format property type', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - 'import \'esmHook/badReturnSourceVal.mjs\'', - ]); - - assert.strictEqual(code, 1); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.match(stderr, /ERR_INVALID_RETURN_PROPERTY_VALUE/); - }); - - it('rejects dynamic imports for all of the error cases checked above', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - Promise.allSettled([ - import('nonexistent/file.mjs'), - import('${fixtures.fileURL('/es-modules/file.unknown')}'), - import('esmHook/badReturnVal.mjs'), - import('esmHook/format.false'), - import('esmHook/format.true'), - import('esmHook/badReturnFormatVal.mjs'), - import('esmHook/unsupportedReturnFormatVal.mjs'), - import('esmHook/badReturnSourceVal.mjs'), - ]).then((results) => { - assert.strictEqual(results.every((result) => result.status === 'rejected'), true); - })`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); -}); - -describe('Loader hooks parsing modules', { concurrency: true }, () => { - it('can parse .js files as ESM', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - import('${fixtures.fileURL('/es-module-loaders/js-as-esm.js')}') - .then((parsedModule) => { - assert.strictEqual(typeof parsedModule, 'object'); - assert.strictEqual(parsedModule.namedExport, 'named-export'); - })`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); - - it('can define .ext files as ESM', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - import('${fixtures.fileURL('/es-modules/file.ext')}') - .then((parsedModule) => { - assert.strictEqual(typeof parsedModule, 'object'); - const { default: defaultExport } = parsedModule; - assert.strictEqual(typeof defaultExport, 'function'); - assert.strictEqual(defaultExport.name, 'iAmReal'); - assert.strictEqual(defaultExport(), true); - })`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); - - it('can predetermine the format in the custom loader resolve hook', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - import('esmHook/preknownFormat.pre') - .then((parsedModule) => { - assert.strictEqual(typeof parsedModule, 'object'); - assert.strictEqual(parsedModule.default, 'hello world'); - })`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); - - it('can provide source for a nonexistent file', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - import('esmHook/virtual.mjs') - .then((parsedModule) => { - assert.strictEqual(typeof parsedModule, 'object'); - assert.strictEqual(typeof parsedModule.default, 'undefined'); - assert.strictEqual(parsedModule.message, 'WOOHOO!'); - })`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); - - it('ensures that loaders have a separate context from userland', async () => { - const { code, signal, stdout, stderr } = await spawnPromisified(execPath, [ - '--no-warnings', - '--experimental-loader', - fixtures.fileURL('/es-module-loaders/hooks-custom.mjs'), - '--input-type=module', - '--eval', - `import assert from 'node:assert'; - import('${fixtures.fileURL('/es-modules/stateful.mjs')}') - .then(({ default: count }) => { - assert.strictEqual(count(), 1); - });`, - ]); - - assert.strictEqual(code, 0); - assert.strictEqual(signal, null); - assert.strictEqual(stdout, ''); - assert.strictEqual(stderr, ''); - }); -}); diff --git a/test/es-module/test-loaders-hidden-from-users.js b/test/es-module/test-loaders-hidden-from-users.js deleted file mode 100644 index 96d1c44154883e..00000000000000 --- a/test/es-module/test-loaders-hidden-from-users.js +++ /dev/null @@ -1,27 +0,0 @@ -// Flags: --expose-internals - -'use strict'; - -require('../common'); -const assert = require('assert'); - -assert.throws( - () => { - require('internal/bootstrap/loaders'); - }, { - code: 'MODULE_NOT_FOUND', - message: /Cannot find module 'internal\/bootstrap\/loaders'/ - } -); - -assert.throws( - () => { - const source = 'module.exports = require("internal/bootstrap/loaders")'; - const { internalBinding } = require('internal/test/binding'); - internalBinding('natives').owo = source; - require('owo'); - }, { - code: 'MODULE_NOT_FOUND', - message: /Cannot find module 'owo'/ - } -); diff --git a/test/es-module/test-loaders-this-value-inside-hook-functions.mjs b/test/es-module/test-loaders-this-value-inside-hook-functions.mjs deleted file mode 100644 index b74b7d9e1e4c30..00000000000000 --- a/test/es-module/test-loaders-this-value-inside-hook-functions.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-this-value-inside-hook-functions.mjs -import '../common/index.mjs'; - -// Actual test is inside the loader module. diff --git a/test/es-module/test-loaders-unknown-builtin-module.mjs b/test/es-module/test-loaders-unknown-builtin-module.mjs deleted file mode 100644 index 85181a2b73b54c..00000000000000 --- a/test/es-module/test-loaders-unknown-builtin-module.mjs +++ /dev/null @@ -1,12 +0,0 @@ -// Flags: --experimental-loader ./test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs -import { expectsError, mustCall } from '../common/index.mjs'; -import assert from 'assert'; - -const unknownBuiltinModule = 'node:unknown-builtin-module'; - -import(unknownBuiltinModule) -.then(assert.fail, expectsError({ - code: 'ERR_UNKNOWN_BUILTIN_MODULE', - message: `No such built-in module: ${unknownBuiltinModule}` -})) -.then(mustCall());