From cb4c2dd33e7c7c1735ea3806af13a39ebe9ed8a8 Mon Sep 17 00:00:00 2001 From: Fran Herrero Date: Tue, 6 Nov 2018 16:36:32 +0000 Subject: [PATCH] test: esm loader unknown builtin module PR-URL: https://github.com/nodejs/node/pull/24183 Reviewed-By: James M Snell Reviewed-By: Gus Caplan Reviewed-By: Ruben Bridgewater --- .../loader-unknown-builtin-module.mjs | 6 ++++++ .../parallel/test-loaders-unknown-builtin-module.mjs | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs create mode 100644 test/parallel/test-loaders-unknown-builtin-module.mjs diff --git a/test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs b/test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs new file mode 100644 index 00000000000000..e7c6c8ff345617 --- /dev/null +++ b/test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs @@ -0,0 +1,6 @@ +export async function resolve(specifier, parent, defaultResolve) { + if (specifier === 'unknown-builtin-module') { + return { url: 'unknown-builtin-module', format: 'builtin' }; + } + return defaultResolve(specifier, parent); +} \ No newline at end of file diff --git a/test/parallel/test-loaders-unknown-builtin-module.mjs b/test/parallel/test-loaders-unknown-builtin-module.mjs new file mode 100644 index 00000000000000..db3cfa3582e9e2 --- /dev/null +++ b/test/parallel/test-loaders-unknown-builtin-module.mjs @@ -0,0 +1,12 @@ +// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-unknown-builtin-module.mjs +import { expectsError, mustCall } from '../common'; +import assert from 'assert'; + +const unknownBuiltinModule = 'unknown-builtin-module'; + +import(unknownBuiltinModule) +.then(assert.fail, expectsError({ + code: 'ERR_UNKNOWN_BUILTIN_MODULE', + message: `No such built-in module: ${unknownBuiltinModule}` +})) +.then(mustCall());