From 9cc2d325877689c7207503b717410493f61c0fb1 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 17:49:58 -0800 Subject: [PATCH 01/17] esm: refactor esm tests out of test/message --- test/message/esm_import_assertion_failed.mjs | 2 -- test/message/esm_import_assertion_failed.out | 18 ------------------ test/message/esm_import_assertion_missing.mjs | 3 --- test/message/esm_import_assertion_missing.out | 19 ------------------- .../esm_import_assertion_unsupported.mjs | 2 -- .../esm_import_assertion_unsupported.out | 19 ------------------- 6 files changed, 63 deletions(-) delete mode 100644 test/message/esm_import_assertion_failed.mjs delete mode 100644 test/message/esm_import_assertion_failed.out delete mode 100644 test/message/esm_import_assertion_missing.mjs delete mode 100644 test/message/esm_import_assertion_missing.out delete mode 100644 test/message/esm_import_assertion_unsupported.mjs delete mode 100644 test/message/esm_import_assertion_unsupported.out diff --git a/test/message/esm_import_assertion_failed.mjs b/test/message/esm_import_assertion_failed.mjs deleted file mode 100644 index 30ea65c3e34e..000000000000 --- a/test/message/esm_import_assertion_failed.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import '../common/index.mjs'; -import 'data:text/javascript,export{}' assert {type:'json'}; diff --git a/test/message/esm_import_assertion_failed.out b/test/message/esm_import_assertion_failed.out deleted file mode 100644 index eed425651664..000000000000 --- a/test/message/esm_import_assertion_failed.out +++ /dev/null @@ -1,18 +0,0 @@ -node:internal/errors:* - ErrorCaptureStackTrace(err); - ^ - -TypeError [ERR_IMPORT_ASSERTION_TYPE_FAILED]: Module "data:text/javascript,export{}" is not of type "json" - at new NodeError (node:internal/errors:*:*) - at handleInvalidType (node:internal/modules/esm/assert:*:*) - at validateAssertions (node:internal/modules/esm/assert:*:*) - at defaultLoad (node:internal/modules/esm/load:*:*) - at ESMLoader.load (node:internal/modules/esm/loader:*:*) - at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*) - at new ModuleJob (node:internal/modules/esm/module_job:*:*) - at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at async ModuleWrap. (node:internal/modules/esm/module_job:*:*) { - code: 'ERR_IMPORT_ASSERTION_TYPE_FAILED' -} -Node.js * diff --git a/test/message/esm_import_assertion_missing.mjs b/test/message/esm_import_assertion_missing.mjs deleted file mode 100644 index 0b402d9e7ff9..000000000000 --- a/test/message/esm_import_assertion_missing.mjs +++ /dev/null @@ -1,3 +0,0 @@ -// Flags: --experimental-json-modules -import '../common/index.mjs'; -import 'data:application/json,{}'; diff --git a/test/message/esm_import_assertion_missing.out b/test/message/esm_import_assertion_missing.out deleted file mode 100644 index a56ec12aeeef..000000000000 --- a/test/message/esm_import_assertion_missing.out +++ /dev/null @@ -1,19 +0,0 @@ -node:internal/errors:* - ErrorCaptureStackTrace(err); - ^ - -TypeError [ERR_IMPORT_ASSERTION_TYPE_MISSING]: Module "data:application/json,{}" needs an import assertion of type "json" - at new NodeError (node:internal/errors:*:*) - at validateAssertions (node:internal/modules/esm/assert:*:*) - at defaultLoad (node:internal/modules/esm/load:*:*) - at ESMLoader.load (node:internal/modules/esm/loader:*:*) - at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*) - at new ModuleJob (node:internal/modules/esm/module_job:*:*) - at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at async ModuleWrap. (node:internal/modules/esm/module_job:*:*) - at async Promise.all (index *) { - code: 'ERR_IMPORT_ASSERTION_TYPE_MISSING' -} - -Node.js * diff --git a/test/message/esm_import_assertion_unsupported.mjs b/test/message/esm_import_assertion_unsupported.mjs deleted file mode 100644 index 86e594ce02ae..000000000000 --- a/test/message/esm_import_assertion_unsupported.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import '../common/index.mjs'; -import '../fixtures/empty.js' assert { type: 'unsupported' }; diff --git a/test/message/esm_import_assertion_unsupported.out b/test/message/esm_import_assertion_unsupported.out deleted file mode 100644 index 0dc3657e43da..000000000000 --- a/test/message/esm_import_assertion_unsupported.out +++ /dev/null @@ -1,19 +0,0 @@ -node:internal/errors:* - ErrorCaptureStackTrace(err); - ^ - -TypeError [ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED]: Import assertion type "unsupported" is unsupported - at new NodeError (node:internal/errors:*:*) - at handleInvalidType (node:internal/modules/esm/assert:*:*) - at validateAssertions (node:internal/modules/esm/assert:*:*) - at defaultLoad (node:internal/modules/esm/load:*:*) - at ESMLoader.load (node:internal/modules/esm/loader:*:*) - at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*) - at new ModuleJob (node:internal/modules/esm/module_job:*:*) - at ESMLoader.#createModuleJob (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at async ModuleWrap. (node:internal/modules/esm/module_job:*:*) { - code: 'ERR_IMPORT_ASSERTION_TYPE_UNSUPPORTED' -} - -Node.js * From 37041fb5e00d2a49e3e1751bd56c8f34ae3ccc28 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 18:06:13 -0800 Subject: [PATCH 02/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 24 +++++++++++++++++++ .../test-esm-import-json-named-export.mjs | 22 +++++++++++++++++ test/es-module/test-esm-syntax-error.mjs | 20 ++++++++++++++++ .../syntax-error-import-multiline.mjs | 5 ++++ .../es-modules/import-json-named-export.mjs | 2 ++ .../esm_display_syntax_error_import.mjs | 6 ----- .../esm_display_syntax_error_import.out | 12 ---------- ..._syntax_error_import_json_named_export.mjs | 4 ---- ..._syntax_error_import_json_named_export.out | 12 ---------- ...esm_display_syntax_error_import_module.mjs | 2 -- ...esm_display_syntax_error_import_module.out | 12 ---------- .../esm_display_syntax_error_module.mjs | 2 -- .../esm_display_syntax_error_module.out | 9 ------- 13 files changed, 73 insertions(+), 59 deletions(-) create mode 100644 test/es-module/test-esm-export-not-found.mjs create mode 100644 test/es-module/test-esm-import-json-named-export.mjs create mode 100644 test/es-module/test-esm-syntax-error.mjs create mode 100644 test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs create mode 100644 test/fixtures/es-modules/import-json-named-export.mjs delete mode 100644 test/message/esm_display_syntax_error_import.mjs delete mode 100644 test/message/esm_display_syntax_error_import.out delete mode 100644 test/message/esm_display_syntax_error_import_json_named_export.mjs delete mode 100644 test/message/esm_display_syntax_error_import_json_named_export.out delete mode 100644 test/message/esm_display_syntax_error_import_module.mjs delete mode 100644 test/message/esm_display_syntax_error_import_module.out delete mode 100644 test/message/esm_display_syntax_error_module.mjs delete mode 100644 test/message/esm_display_syntax_error_module.out diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs new file mode 100644 index 000000000000..c4ff861e7ebd --- /dev/null +++ b/test/es-module/test-esm-export-not-found.mjs @@ -0,0 +1,24 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +[ + path('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/es-module-loaders/syntax-error-import.mjs'), + path('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/es-module-loaders/syntax-error-import-multiline.mjs'), +].forEach((entry) => { + const child = spawn(execPath, [entry]); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + stderr += data; + }); + child.on('close', () => { + ok(stderr.toString().includes( + 'SyntaxError: The requested module \'./module-named-exports.mjs\' ' + + 'does not provide an export named \'notfound\'' + )); + }); +}); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs new file mode 100644 index 000000000000..c8bf9f280d01 --- /dev/null +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -0,0 +1,22 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +const child = spawn(execPath, [ + '--experimental-json-modules', + path('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/es-modules/import-json-named-export.mjs'), +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', () => { + ok(stderr.toString().includes( + 'SyntaxError: The requested module \'../experimental.json\' ' + + 'does not provide an export named \'ofLife\'' + )); +}); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs new file mode 100644 index 000000000000..b9961814d945 --- /dev/null +++ b/test/es-module/test-esm-syntax-error.mjs @@ -0,0 +1,20 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +const child = spawn(execPath, [ + path('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/es-module-loaders/syntax-error.mjs'), +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', () => { + ok(stderr.toString().includes( + 'SyntaxError: Malformed arrow function parameter list' + )); +}); diff --git a/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs b/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs new file mode 100644 index 000000000000..23bf63f5c58d --- /dev/null +++ b/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs @@ -0,0 +1,5 @@ +/* eslint-disable no-unused-vars */ +import { + foo, + notfound +} from './module-named-exports.mjs'; diff --git a/test/fixtures/es-modules/import-json-named-export.mjs b/test/fixtures/es-modules/import-json-named-export.mjs new file mode 100644 index 000000000000..f491e8c252d4 --- /dev/null +++ b/test/fixtures/es-modules/import-json-named-export.mjs @@ -0,0 +1,2 @@ +/* eslint-disable no-unused-vars */ +import { ofLife } from '../experimental.json' assert { type: 'json' }; diff --git a/test/message/esm_display_syntax_error_import.mjs b/test/message/esm_display_syntax_error_import.mjs deleted file mode 100644 index 2173cb2b2e3a..000000000000 --- a/test/message/esm_display_syntax_error_import.mjs +++ /dev/null @@ -1,6 +0,0 @@ -/* eslint-disable no-unused-vars */ -import '../common/index.mjs'; -import { - foo, - notfound -} from '../fixtures/es-module-loaders/module-named-exports.mjs'; diff --git a/test/message/esm_display_syntax_error_import.out b/test/message/esm_display_syntax_error_import.out deleted file mode 100644 index babdcfc934bd..000000000000 --- a/test/message/esm_display_syntax_error_import.out +++ /dev/null @@ -1,12 +0,0 @@ -file:///*/test/message/esm_display_syntax_error_import.mjs:5 - notfound - ^^^^^^^^ -SyntaxError: The requested module '../fixtures/es-module-loaders/module-named-exports.mjs' does not provide an export named 'notfound' - at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*) - at async ModuleJob.run (node:internal/modules/esm/module_job:*:*) - at async Promise.all (index 0) - at async ESMLoader.import (node:internal/modules/esm/loader:*:*) - at async loadESM (node:internal/process/esm_loader:*:*) - at async handleMainPromise (node:internal/modules/run_main:*:*) - -Node.js * diff --git a/test/message/esm_display_syntax_error_import_json_named_export.mjs b/test/message/esm_display_syntax_error_import_json_named_export.mjs deleted file mode 100644 index fc1434046785..000000000000 --- a/test/message/esm_display_syntax_error_import_json_named_export.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Flags: --experimental-json-modules --no-warnings -/* eslint-disable no-unused-vars */ -import '../common/index.mjs'; -import { ofLife } from '../fixtures/experimental.json' assert { type: 'json' }; diff --git a/test/message/esm_display_syntax_error_import_json_named_export.out b/test/message/esm_display_syntax_error_import_json_named_export.out deleted file mode 100644 index d4636489f27c..000000000000 --- a/test/message/esm_display_syntax_error_import_json_named_export.out +++ /dev/null @@ -1,12 +0,0 @@ -file:///*/test/message/esm_display_syntax_error_import_json_named_export.mjs:* -import { ofLife } from '../fixtures/experimental.json' assert { type: 'json' }; - ^^^^^^ -SyntaxError: The requested module '../fixtures/experimental.json' does not provide an export named 'ofLife' - at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*) - at async ModuleJob.run (node:internal/modules/esm/module_job:*:*) - at async Promise.all (index 0) - at async ESMLoader.import (node:internal/modules/esm/loader:*:*) - at async loadESM (node:internal/process/esm_loader:*:*) - at async handleMainPromise (node:internal/modules/run_main:*:*) - -Node.js * diff --git a/test/message/esm_display_syntax_error_import_module.mjs b/test/message/esm_display_syntax_error_import_module.mjs deleted file mode 100644 index c0345c44fb3f..000000000000 --- a/test/message/esm_display_syntax_error_import_module.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import '../common/index.mjs'; -import '../fixtures/es-module-loaders/syntax-error-import.mjs'; diff --git a/test/message/esm_display_syntax_error_import_module.out b/test/message/esm_display_syntax_error_import_module.out deleted file mode 100644 index af95ab469f5a..000000000000 --- a/test/message/esm_display_syntax_error_import_module.out +++ /dev/null @@ -1,12 +0,0 @@ -file:///*/test/fixtures/es-module-loaders/syntax-error-import.mjs:1 -import { foo, notfound } from './module-named-exports.mjs'; - ^^^^^^^^ -SyntaxError: The requested module './module-named-exports.mjs' does not provide an export named 'notfound' - at ModuleJob._instantiate (node:internal/modules/esm/module_job:*:*) - at async ModuleJob.run (node:internal/modules/esm/module_job:*:*) - at async Promise.all (index 0) - at async ESMLoader.import (node:internal/modules/esm/loader:*:*) - at async loadESM (node:internal/process/esm_loader:*:*) - at async handleMainPromise (node:internal/modules/run_main:*:*) - -Node.js * diff --git a/test/message/esm_display_syntax_error_module.mjs b/test/message/esm_display_syntax_error_module.mjs deleted file mode 100644 index da40a4ead8d3..000000000000 --- a/test/message/esm_display_syntax_error_module.mjs +++ /dev/null @@ -1,2 +0,0 @@ -import '../common/index.mjs'; -import '../fixtures/es-module-loaders/syntax-error.mjs'; diff --git a/test/message/esm_display_syntax_error_module.out b/test/message/esm_display_syntax_error_module.out deleted file mode 100644 index 622e85ec7592..000000000000 --- a/test/message/esm_display_syntax_error_module.out +++ /dev/null @@ -1,9 +0,0 @@ -file:///*/test/fixtures/es-module-loaders/syntax-error.mjs:2 -await async () => 0; -^^^^^^^^^^^^^ - -SyntaxError: Malformed arrow function parameter list - at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:*:*) - at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*) - -Node.js * From 6b8320b6cb38e502b06af899c930688beb42487f Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 18:48:39 -0800 Subject: [PATCH 03/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-loader-not-found.mjs | 25 ++++++++++++++++++++ test/fixtures/print-error-message.js | 1 + test/message/esm_loader_not_found.mjs | 3 --- test/message/esm_loader_not_found.out | 20 ---------------- 4 files changed, 26 insertions(+), 23 deletions(-) create mode 100644 test/es-module/test-esm-loader-not-found.mjs create mode 100644 test/fixtures/print-error-message.js delete mode 100644 test/message/esm_loader_not_found.mjs delete mode 100644 test/message/esm_loader_not_found.out diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs new file mode 100644 index 000000000000..e7b67de8278e --- /dev/null +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -0,0 +1,25 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +const child = spawn(execPath, [ + '--experimental-loader', + 'i-dont-exist', + path('/print-error-message.js') +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', () => { + stderr = stderr.toString() + ok(stderr.includes( + 'Error [ERR_MODULE_NOT_FOUND]: Cannot find package \'i-dont-exist\' ' + + 'imported from' + )); + ok(!stderr.includes('Bad command or file name')); +}); diff --git a/test/fixtures/print-error-message.js b/test/fixtures/print-error-message.js new file mode 100644 index 000000000000..0650bfbd52ba --- /dev/null +++ b/test/fixtures/print-error-message.js @@ -0,0 +1 @@ +console.error('Bad command or file name'); diff --git a/test/message/esm_loader_not_found.mjs b/test/message/esm_loader_not_found.mjs deleted file mode 100644 index 2b47e5a03ec9..000000000000 --- a/test/message/esm_loader_not_found.mjs +++ /dev/null @@ -1,3 +0,0 @@ -// Flags: --experimental-loader i-dont-exist -import '../common/index.mjs'; -console.log('This should not be printed'); diff --git a/test/message/esm_loader_not_found.out b/test/message/esm_loader_not_found.out deleted file mode 100644 index 841e97d679ea..000000000000 --- a/test/message/esm_loader_not_found.out +++ /dev/null @@ -1,20 +0,0 @@ -(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time -(Use `* --trace-warnings ...` to show where the warning was created) -node:internal/errors:* - ErrorCaptureStackTrace(err); - ^ -Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' imported from * - at new NodeError (node:internal/errors:*:*) - at packageResolve (node:internal/modules/esm/resolve:*:*) - at moduleResolve (node:internal/modules/esm/resolve:*:*) - at defaultResolve (node:internal/modules/esm/resolve:*:*) - at ESMLoader.resolve (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at ESMLoader.import (node:internal/modules/esm/loader:*:*) - at initializeLoader (node:internal/process/esm_loader:*:*) - at loadESM (node:internal/process/esm_loader:*:*) - at runMainESM (node:internal/modules/run_main:*:*) { - code: 'ERR_MODULE_NOT_FOUND' -} - -Node.js * From 72e8a700605ce72815663e0dba5454cf4ad2b50d Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 20:14:41 -0800 Subject: [PATCH 04/17] fixup! esm: refactor esm tests out of test/message --- ...est-esm-module-not-found-commonjs-hint.mjs | 33 +++++++++++++++++++ .../esm_loader_not_found_cjs_hint_bare.mjs | 5 --- .../esm_loader_not_found_cjs_hint_bare.js | 17 ---------- .../esm_loader_not_found_cjs_hint_bare.out | 18 ---------- ...esm_loader_not_found_cjs_hint_relative.mjs | 3 -- ...esm_loader_not_found_cjs_hint_relative.out | 22 ------------- 6 files changed, 33 insertions(+), 65 deletions(-) create mode 100644 test/es-module/test-esm-module-not-found-commonjs-hint.mjs delete mode 100644 test/fixtures/esm_loader_not_found_cjs_hint_bare.mjs delete mode 100644 test/message/esm_loader_not_found_cjs_hint_bare.js delete mode 100644 test/message/esm_loader_not_found_cjs_hint_bare.out delete mode 100644 test/message/esm_loader_not_found_cjs_hint_relative.mjs delete mode 100644 test/message/esm_loader_not_found_cjs_hint_relative.out diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs new file mode 100644 index 000000000000..9496469bef30 --- /dev/null +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -0,0 +1,33 @@ +import '../common/index.mjs'; +import { fixturesDir } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +[ + { + input: 'import "./print-error-message"', + expected: 'Did you mean to import ../print-error-message.js?' + }, + { + input: 'import obj from "some_module/obj"', + expected: 'Did you mean to import some_module/obj.js?' + }, +].forEach(({ input, expected }) => { + const child = spawn(execPath, [ + '--input-type=module', + '--eval', + input, + ], { + cwd: fixturesDir + }); + + let stderr = ''; + child.stderr.setEncoding('utf8'); + child.stderr.on('data', (data) => { + stderr += data; + }); + child.on('close', () => { + ok(stderr.toString().includes(expected)); + }); +}); diff --git a/test/fixtures/esm_loader_not_found_cjs_hint_bare.mjs b/test/fixtures/esm_loader_not_found_cjs_hint_bare.mjs deleted file mode 100644 index 4eb5f190af43..000000000000 --- a/test/fixtures/esm_loader_not_found_cjs_hint_bare.mjs +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -import obj from 'some_module/obj'; - -throw new Error('Should have errored'); diff --git a/test/message/esm_loader_not_found_cjs_hint_bare.js b/test/message/esm_loader_not_found_cjs_hint_bare.js deleted file mode 100644 index 437fa2d3d430..000000000000 --- a/test/message/esm_loader_not_found_cjs_hint_bare.js +++ /dev/null @@ -1,17 +0,0 @@ -'use strict'; - -require('../common'); -const { spawn } = require('child_process'); -const { join } = require('path'); -const { fixturesDir } = require('../common/fixtures'); - -spawn( - process.execPath, - [ - join(fixturesDir, 'esm_loader_not_found_cjs_hint_bare.mjs'), - ], - { - cwd: fixturesDir, - stdio: 'inherit' - } -); diff --git a/test/message/esm_loader_not_found_cjs_hint_bare.out b/test/message/esm_loader_not_found_cjs_hint_bare.out deleted file mode 100644 index eaa758742ff6..000000000000 --- a/test/message/esm_loader_not_found_cjs_hint_bare.out +++ /dev/null @@ -1,18 +0,0 @@ -node:internal/process/esm_loader:* - internalBinding('errors').triggerUncaughtException( - ^ - -Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*fixtures*node_modules*some_module*obj' imported from *test*fixtures*esm_loader_not_found_cjs_hint_bare.mjs -Did you mean to import some_module/obj.js? - at new NodeError (node:internal/errors:*:*) - at finalizeResolution (node:internal/modules/esm/resolve:*:*) - at moduleResolve (node:internal/modules/esm/resolve:*:*) - at defaultResolve (node:internal/modules/esm/resolve:*:*) - at ESMLoader.resolve (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at ModuleWrap. (node:internal/modules/esm/module_job:*:*) - at link (node:internal/modules/esm/module_job:*:*) { - code: 'ERR_MODULE_NOT_FOUND' -} - -Node.js * diff --git a/test/message/esm_loader_not_found_cjs_hint_relative.mjs b/test/message/esm_loader_not_found_cjs_hint_relative.mjs deleted file mode 100644 index 928186318bb0..000000000000 --- a/test/message/esm_loader_not_found_cjs_hint_relative.mjs +++ /dev/null @@ -1,3 +0,0 @@ -// Flags: --experimental-loader ./test/common/fixtures -import '../common/index.mjs'; -console.log('This should not be printed'); diff --git a/test/message/esm_loader_not_found_cjs_hint_relative.out b/test/message/esm_loader_not_found_cjs_hint_relative.out deleted file mode 100644 index 0bd9ab7336c2..000000000000 --- a/test/message/esm_loader_not_found_cjs_hint_relative.out +++ /dev/null @@ -1,22 +0,0 @@ -(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time -(Use `* --trace-warnings ...` to show where the warning was created) -node:internal/process/esm_loader:* - internalBinding('errors').triggerUncaughtException( - ^ - -Error [ERR_MODULE_NOT_FOUND]: Cannot find module '*test*common*fixtures' imported from * -Did you mean to import ./test/common/fixtures.js? - at new NodeError (node:internal/errors:*:*) - at finalizeResolution (node:internal/modules/esm/resolve:*:*) - at moduleResolve (node:internal/modules/esm/resolve:*:*) - at defaultResolve (node:internal/modules/esm/resolve:*:*) - at ESMLoader.resolve (node:internal/modules/esm/loader:*:*) - at ESMLoader.getModuleJob (node:internal/modules/esm/loader:*:*) - at ESMLoader.import (node:internal/modules/esm/loader:*:*) - at initializeLoader (node:internal/process/esm_loader:*:*) - at loadESM (node:internal/process/esm_loader:*:*) - at runMainESM (node:internal/modules/run_main:*:*) { - code: 'ERR_MODULE_NOT_FOUND' -} - -Node.js * From caab55c4c0426a656af4566d2cb3bee9ae71ed4b Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 20:23:26 -0800 Subject: [PATCH 05/17] fixup! esm: refactor esm tests out of test/message --- .../test-esm-loader-with-syntax-error.mjs | 24 +++++++++++++++++++ test/message/esm_loader_syntax_error.mjs | 3 --- test/message/esm_loader_syntax_error.out | 12 ---------- 3 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 test/es-module/test-esm-loader-with-syntax-error.mjs delete mode 100644 test/message/esm_loader_syntax_error.mjs delete mode 100644 test/message/esm_loader_syntax_error.out diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs new file mode 100644 index 000000000000..fc796fa1d112 --- /dev/null +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -0,0 +1,24 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +const child = spawn(execPath, [ + '--experimental-loader', + path('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/es-module-loaders/syntax-error.mjs'), + path('/print-error-message.js'), +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', () => { + stderr = stderr.toString() + ok(stderr.includes( + 'SyntaxError: Malformed arrow function parameter list' + )); + ok(!stderr.includes('Bad command or file name')); +}); diff --git a/test/message/esm_loader_syntax_error.mjs b/test/message/esm_loader_syntax_error.mjs deleted file mode 100644 index 68cde42e5856..000000000000 --- a/test/message/esm_loader_syntax_error.mjs +++ /dev/null @@ -1,3 +0,0 @@ -// Flags: --experimental-loader ./test/fixtures/es-module-loaders/syntax-error.mjs -import '../common/index.mjs'; -console.log('This should not be printed'); diff --git a/test/message/esm_loader_syntax_error.out b/test/message/esm_loader_syntax_error.out deleted file mode 100644 index fdced9fc96b9..000000000000 --- a/test/message/esm_loader_syntax_error.out +++ /dev/null @@ -1,12 +0,0 @@ -(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time -(Use `* --trace-warnings ...` to show where the warning was created) -file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2 -await async () => 0; -^^^^^^^^^^^^^ - -SyntaxError: Malformed arrow function parameter list - at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:*:*) - at ESMLoader.moduleProvider (node:internal/modules/esm/loader:*:*) - at async link (node:internal/modules/esm/module_job:*:*) - -Node.js * From 54821b74fc9bd14a4ef5c1037541f4f4a0bcb200 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 20:29:21 -0800 Subject: [PATCH 06/17] fixup! esm: refactor esm tests out of test/message --- .../test-esm-loader-obsolete-hooks.mjs | 26 +++++++++++++++++++ .../test-esm-loader-obsolete-hooks.mjs | 4 --- .../test-esm-loader-obsolete-hooks.out | 11 -------- 3 files changed, 26 insertions(+), 15 deletions(-) create mode 100644 test/es-module/test-esm-loader-obsolete-hooks.mjs delete mode 100644 test/message/test-esm-loader-obsolete-hooks.mjs delete mode 100644 test/message/test-esm-loader-obsolete-hooks.out diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs new file mode 100644 index 000000000000..0675df384cae --- /dev/null +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -0,0 +1,26 @@ +import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; +import { ok } from 'assert'; +import { spawn } from 'child_process'; +import { execPath } from 'process'; + +const child = spawn(execPath, [ + '--no-warnings', + '--throw-deprecation', + '--experimental-loader', + path('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/es-module-loaders/hooks-obsolete.mjs'), + path('/print-error-message.js') +]); + +let stderr = ''; +child.stderr.setEncoding('utf8'); +child.stderr.on('data', (data) => { + stderr += data; +}); +child.on('close', () => { + stderr = stderr.toString() + ok(stderr.includes( + 'DeprecationWarning: Obsolete loader hook(s) supplied and will be ' + + 'ignored: dynamicInstantiate, getFormat, getSource, transformSource' + )); +}); diff --git a/test/message/test-esm-loader-obsolete-hooks.mjs b/test/message/test-esm-loader-obsolete-hooks.mjs deleted file mode 100644 index 9a6a9c48057b..000000000000 --- a/test/message/test-esm-loader-obsolete-hooks.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Flags: --no-warnings --throw-deprecation --experimental-loader ./test/fixtures/es-module-loaders/hooks-obsolete.mjs -/* eslint-disable node-core/require-common-first, node-core/required-modules */ - -await import('whatever'); diff --git a/test/message/test-esm-loader-obsolete-hooks.out b/test/message/test-esm-loader-obsolete-hooks.out deleted file mode 100644 index 5453cefe2090..000000000000 --- a/test/message/test-esm-loader-obsolete-hooks.out +++ /dev/null @@ -1,11 +0,0 @@ -node:internal/process/warning:* - throw warning; - ^ - -DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: dynamicInstantiate, getFormat, getSource, transformSource - at Function.pluckHooks (node:internal/modules/esm/loader:*:*) - at ESMLoader.addCustomLoaders (node:internal/modules/esm/loader:*:*) - at initializeLoader (node:internal/process/esm_loader:*:*) - at async loadESM (node:internal/process/esm_loader:*:*) - at async handleMainPromise (node:internal/modules/run_main:*:*) -Node.js * \ No newline at end of file From 9be8289b985473253760cc09a2c40c1c8cacc894 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 20:33:36 -0800 Subject: [PATCH 07/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-loader-not-found.mjs | 4 ++-- test/es-module/test-esm-loader-obsolete-hooks.mjs | 4 ++-- test/es-module/test-esm-loader-with-syntax-error.mjs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index e7b67de8278e..ae6b13bc9b21 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -7,7 +7,7 @@ import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', 'i-dont-exist', - path('/print-error-message.js') + path('/print-error-message.js'), ]); let stderr = ''; @@ -16,7 +16,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString() + stderr = stderr.toString(); ok(stderr.includes( 'Error [ERR_MODULE_NOT_FOUND]: Cannot find package \'i-dont-exist\' ' + 'imported from' diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 0675df384cae..30dcb32452be 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -9,7 +9,7 @@ const child = spawn(execPath, [ '--throw-deprecation', '--experimental-loader', path('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/es-module-loaders/hooks-obsolete.mjs'), - path('/print-error-message.js') + path('/print-error-message.js'), ]); let stderr = ''; @@ -18,7 +18,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString() + stderr = stderr.toString(); ok(stderr.includes( 'DeprecationWarning: Obsolete loader hook(s) supplied and will be ' + 'ignored: dynamicInstantiate, getFormat, getSource, transformSource' diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index fc796fa1d112..260d484e132b 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -16,7 +16,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString() + stderr = stderr.toString(); ok(stderr.includes( 'SyntaxError: Malformed arrow function parameter list' )); From 12c3457ef5a54d33090798dd115082875556cdd6 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 29 Dec 2021 20:40:47 -0800 Subject: [PATCH 08/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 24 ++++++++++++++----- .../syntax-error-import-multiline.mjs | 5 ---- .../es-module-loaders/syntax-error-import.mjs | 1 - 3 files changed, 18 insertions(+), 12 deletions(-) delete mode 100644 test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs delete mode 100644 test/fixtures/es-module-loaders/syntax-error-import.mjs diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index c4ff861e7ebd..cc0d611f941d 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -1,14 +1,26 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; +import { fixturesDir } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; +import { join } from 'path'; import { execPath } from 'process'; -[ - path('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/es-module-loaders/syntax-error-import.mjs'), - path('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/es-module-loaders/syntax-error-import-multiline.mjs'), -].forEach((entry) => { - const child = spawn(execPath, [entry]); +const importStatement = + 'import { foo, notfound } from \'./module-named-exports.mjs\';'; +const importStatementMultiline = `import { + foo, + notfound +} from './module-named-exports.mjs'; +`; + +[importStatement, importStatementMultiline].forEach((input) => { + const child = spawn(execPath, [ + '--input-type=module', + '--eval', + input, + ], { + cwd: join(fixturesDir, 'es-module-loaders') + }); let stderr = ''; child.stderr.setEncoding('utf8'); diff --git a/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs b/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs deleted file mode 100644 index 23bf63f5c58d..000000000000 --- a/test/fixtures/es-module-loaders/syntax-error-import-multiline.mjs +++ /dev/null @@ -1,5 +0,0 @@ -/* eslint-disable no-unused-vars */ -import { - foo, - notfound -} from './module-named-exports.mjs'; diff --git a/test/fixtures/es-module-loaders/syntax-error-import.mjs b/test/fixtures/es-module-loaders/syntax-error-import.mjs deleted file mode 100644 index 3a6bc5effc19..000000000000 --- a/test/fixtures/es-module-loaders/syntax-error-import.mjs +++ /dev/null @@ -1 +0,0 @@ -import { foo, notfound } from './module-named-exports.mjs'; From 3ea5e1bd72767f72e8f5e5d70a2679b91c2e384d Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 30 Dec 2021 11:55:21 -0800 Subject: [PATCH 09/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 2 +- test/es-module/test-esm-import-json-named-export.mjs | 2 +- test/es-module/test-esm-loader-not-found.mjs | 1 - test/es-module/test-esm-loader-obsolete-hooks.mjs | 1 - test/es-module/test-esm-loader-with-syntax-error.mjs | 1 - test/es-module/test-esm-module-not-found-commonjs-hint.mjs | 2 +- test/es-module/test-esm-syntax-error.mjs | 2 +- 7 files changed, 4 insertions(+), 7 deletions(-) diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index cc0d611f941d..93be68fd0246 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -28,7 +28,7 @@ const importStatementMultiline = `import { stderr += data; }); child.on('close', () => { - ok(stderr.toString().includes( + ok(stderr.includes( 'SyntaxError: The requested module \'./module-named-exports.mjs\' ' + 'does not provide an export named \'notfound\'' )); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index c8bf9f280d01..5c9751caff25 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -15,7 +15,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.toString().includes( + ok(stderr.includes( 'SyntaxError: The requested module \'../experimental.json\' ' + 'does not provide an export named \'ofLife\'' )); diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index ae6b13bc9b21..cf1ce88075da 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -16,7 +16,6 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString(); ok(stderr.includes( 'Error [ERR_MODULE_NOT_FOUND]: Cannot find package \'i-dont-exist\' ' + 'imported from' diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 30dcb32452be..a64456bdbe0a 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -18,7 +18,6 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString(); ok(stderr.includes( 'DeprecationWarning: Obsolete loader hook(s) supplied and will be ' + 'ignored: dynamicInstantiate, getFormat, getSource, transformSource' diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 260d484e132b..80b15b42241d 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -16,7 +16,6 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - stderr = stderr.toString(); ok(stderr.includes( 'SyntaxError: Malformed arrow function parameter list' )); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index 9496469bef30..a406382dbf41 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -28,6 +28,6 @@ import { execPath } from 'process'; stderr += data; }); child.on('close', () => { - ok(stderr.toString().includes(expected)); + ok(stderr.includes(expected)); }); }); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index b9961814d945..8641605a9741 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -14,7 +14,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.toString().includes( + ok(stderr.includes( 'SyntaxError: Malformed arrow function parameter list' )); }); From d64d044beb3ae715207625d5973e858f505fe768 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 30 Dec 2021 12:12:53 -0800 Subject: [PATCH 10/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 10 ++++++---- test/es-module/test-esm-import-json-named-export.mjs | 9 +++++---- test/es-module/test-esm-loader-not-found.mjs | 9 +++++---- test/es-module/test-esm-loader-with-syntax-error.mjs | 4 +--- .../test-esm-module-not-found-commonjs-hint.mjs | 5 +++-- test/es-module/test-esm-syntax-error.mjs | 4 +--- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index 93be68fd0246..1dc44e2bbac9 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -28,9 +28,11 @@ const importStatementMultiline = `import { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'SyntaxError: The requested module \'./module-named-exports.mjs\' ' + - 'does not provide an export named \'notfound\'' - )); + // SyntaxError: The requested module './module-named-exports.mjs' + // does not provide an export named 'notfound' + ok(stderr.includes('SyntaxError:')); + // The quotes ensure that the path starts with ./ and not ../ + ok(stderr.includes('\'./module-named-exports.mjs\'')); + ok(stderr.includes('notfound')); }); }); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index 5c9751caff25..73e8e9184972 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -15,8 +15,9 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'SyntaxError: The requested module \'../experimental.json\' ' + - 'does not provide an export named \'ofLife\'' - )); + // SyntaxError: The requested module '../experimental.json' + // does not provide an export named 'ofLife' + ok(stderr.includes('SyntaxError:')); + ok(stderr.includes('\'../experimental.json\'')); + ok(stderr.includes('\'ofLife\'')); }); diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index cf1ce88075da..545127eb2412 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -16,9 +16,10 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'Error [ERR_MODULE_NOT_FOUND]: Cannot find package \'i-dont-exist\' ' + - 'imported from' - )); + // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' + // imported from + ok(stderr.includes('ERR_MODULE_NOT_FOUND')); + ok(stderr.includes('\'i-dont-exist\'')); + ok(!stderr.includes('Bad command or file name')); }); diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 80b15b42241d..d8ad0b5db276 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -16,8 +16,6 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'SyntaxError: Malformed arrow function parameter list' - )); + ok(stderr.includes('SyntaxError:')); ok(!stderr.includes('Bad command or file name')); }); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index a406382dbf41..ffe26b6980ff 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -7,11 +7,12 @@ import { execPath } from 'process'; [ { input: 'import "./print-error-message"', - expected: 'Did you mean to import ../print-error-message.js?' + // Did you mean to import ../print-error-message.js? + expected: ' ../print-error-message.js?' }, { input: 'import obj from "some_module/obj"', - expected: 'Did you mean to import some_module/obj.js?' + expected: ' some_module/obj.js?' }, ].forEach(({ input, expected }) => { const child = spawn(execPath, [ diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index 8641605a9741..a40aba09d845 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -14,7 +14,5 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'SyntaxError: Malformed arrow function parameter list' - )); + ok(stderr.includes('SyntaxError:')); }); From b042d99120c37570a54b7bed8ca9db2401c98f5e Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 30 Dec 2021 20:06:37 -0800 Subject: [PATCH 11/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 7 ++++--- test/es-module/test-esm-import-json-named-export.mjs | 6 +++--- test/es-module/test-esm-loader-not-found.mjs | 6 +++--- test/es-module/test-esm-loader-obsolete-hooks.mjs | 2 +- test/es-module/test-esm-loader-with-syntax-error.mjs | 4 ++-- test/es-module/test-esm-module-not-found-commonjs-hint.mjs | 2 +- test/es-module/test-esm-syntax-error.mjs | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index 1dc44e2bbac9..6d3644d87162 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -30,9 +30,10 @@ const importStatementMultiline = `import { child.on('close', () => { // SyntaxError: The requested module './module-named-exports.mjs' // does not provide an export named 'notfound' - ok(stderr.includes('SyntaxError:')); + ok(stderr.includes('SyntaxError:') || console.error(stderr)); // The quotes ensure that the path starts with ./ and not ../ - ok(stderr.includes('\'./module-named-exports.mjs\'')); - ok(stderr.includes('notfound')); + ok(stderr.includes('\'./module-named-exports.mjs\'') || + console.error(stderr)); + ok(stderr.includes('notfound') || console.error(stderr)); }); }); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index 73e8e9184972..7db7522f1f4d 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -17,7 +17,7 @@ child.stderr.on('data', (data) => { child.on('close', () => { // SyntaxError: The requested module '../experimental.json' // does not provide an export named 'ofLife' - ok(stderr.includes('SyntaxError:')); - ok(stderr.includes('\'../experimental.json\'')); - ok(stderr.includes('\'ofLife\'')); + ok(stderr.includes('SyntaxError:') || console.error(stderr)); + ok(stderr.includes('\'../experimental.json\'') || console.error(stderr)); + ok(stderr.includes('\'ofLife\'') || console.error(stderr)); }); diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index 545127eb2412..c9e55733944f 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -18,8 +18,8 @@ child.stderr.on('data', (data) => { child.on('close', () => { // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' // imported from - ok(stderr.includes('ERR_MODULE_NOT_FOUND')); - ok(stderr.includes('\'i-dont-exist\'')); + ok(stderr.includes('ERR_MODULE_NOT_FOUND') || console.error(stderr)); + ok(stderr.includes('\'i-dont-exist\'') || console.error(stderr)); - ok(!stderr.includes('Bad command or file name')); + ok(!stderr.includes('Bad command or file name') || console.error(stderr)); }); diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index a64456bdbe0a..37c85ce85b24 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -21,5 +21,5 @@ child.on('close', () => { ok(stderr.includes( 'DeprecationWarning: Obsolete loader hook(s) supplied and will be ' + 'ignored: dynamicInstantiate, getFormat, getSource, transformSource' - )); + ) || console.error(stderr)); }); diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index d8ad0b5db276..6101bcfda4b2 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -16,6 +16,6 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes('SyntaxError:')); - ok(!stderr.includes('Bad command or file name')); + ok(stderr.includes('SyntaxError:') || console.error(stderr)); + ok(!stderr.includes('Bad command or file name') || console.error(stderr)); }); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index ffe26b6980ff..495c085dafe3 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -29,6 +29,6 @@ import { execPath } from 'process'; stderr += data; }); child.on('close', () => { - ok(stderr.includes(expected)); + ok(stderr.includes(expected) || console.error(stderr)); }); }); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index a40aba09d845..0d688f85ff5e 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -14,5 +14,5 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes('SyntaxError:')); + ok(stderr.includes('SyntaxError:') || console.error(stderr)); }); From 13861f0639abb705ee4f07f5c40a95e09b446d1e Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Thu, 30 Dec 2021 22:59:47 -0800 Subject: [PATCH 12/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-import-json-named-export.mjs | 3 +-- test/es-module/test-esm-loader-not-found.mjs | 3 +-- test/es-module/test-esm-loader-obsolete-hooks.mjs | 5 ++--- test/es-module/test-esm-loader-with-syntax-error.mjs | 5 ++--- test/es-module/test-esm-syntax-error.mjs | 3 +-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index 7db7522f1f4d..bfb431ceeb47 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -1,12 +1,11 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-json-modules', - path('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/es-modules/import-json-named-export.mjs'), + './test/fixtures/es-modules/import-json-named-export.mjs', ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index c9e55733944f..c077776ac6bf 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -1,5 +1,4 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -7,7 +6,7 @@ import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', 'i-dont-exist', - path('/print-error-message.js'), + './test/fixtures/print-error-message.js', ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 37c85ce85b24..1b4ceca38fd2 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -1,5 +1,4 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -8,8 +7,8 @@ const child = spawn(execPath, [ '--no-warnings', '--throw-deprecation', '--experimental-loader', - path('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/es-module-loaders/hooks-obsolete.mjs'), - path('/print-error-message.js'), + './test/fixtures/es-module-loaders/hooks-obsolete.mjs', + './test/fixtures/print-error-message.js', ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 6101bcfda4b2..5dd3087d6b99 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,13 +1,12 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', - path('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/es-module-loaders/syntax-error.mjs'), - path('/print-error-message.js'), + './test/fixtures/es-module-loaders/syntax-error.mjs', + './test/fixtures/print-error-message.js', ]); let stderr = ''; diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index 0d688f85ff5e..d49b5a329a0a 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -1,11 +1,10 @@ import '../common/index.mjs'; -import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ - path('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/es-module-loaders/syntax-error.mjs'), + './test/fixtures/es-module-loaders/syntax-error.mjs', ]); let stderr = ''; From c191d042b7af7504e8d34bdfd1f1a8143c8e457e Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Fri, 31 Dec 2021 14:13:00 -0800 Subject: [PATCH 13/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-loader-obsolete-hooks.mjs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 1b4ceca38fd2..24e6ae0f657f 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -17,8 +17,11 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes( - 'DeprecationWarning: Obsolete loader hook(s) supplied and will be ' + - 'ignored: dynamicInstantiate, getFormat, getSource, transformSource' - ) || console.error(stderr)); + // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: + // dynamicInstantiate, getFormat, getSource, transformSource + ok(stderr.includes('DeprecationWarning:') || console.error(stderr)); + ok(stderr.includes('dynamicInstantiate') || console.error(stderr)); + ok(stderr.includes('getFormat') || console.error(stderr)); + ok(stderr.includes('getSource') || console.error(stderr)); + ok(stderr.includes('transformSource') || console.error(stderr)); }); From 17e01c392c1d7b10ddbe756174108a618c439916 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 3 Jan 2022 21:40:57 -0800 Subject: [PATCH 14/17] fixup! esm: refactor esm tests out of test/message --- test/common/fixtures.js | 6 ++++++ test/common/fixtures.mjs | 2 ++ test/es-module/test-esm-export-not-found.mjs | 5 ++--- test/es-module/test-esm-import-json-named-export.mjs | 3 ++- test/es-module/test-esm-loader-not-found.mjs | 3 ++- test/es-module/test-esm-loader-obsolete-hooks.mjs | 5 +++-- test/es-module/test-esm-loader-with-syntax-error.mjs | 5 +++-- test/es-module/test-esm-module-not-found-commonjs-hint.mjs | 2 +- test/es-module/test-esm-syntax-error.mjs | 3 ++- 9 files changed, 23 insertions(+), 11 deletions(-) diff --git a/test/common/fixtures.js b/test/common/fixtures.js index e5e1d887df52..3ee87e8b2d7b 100644 --- a/test/common/fixtures.js +++ b/test/common/fixtures.js @@ -2,6 +2,7 @@ const path = require('path'); const fs = require('fs'); +const { pathToFileURL } = require('url'); const fixturesDir = path.join(__dirname, '..', 'fixtures'); @@ -9,6 +10,10 @@ function fixturesPath(...args) { return path.join(fixturesDir, ...args); } +function fixturesFileURL(...args) { + return pathToFileURL(fixturesPath(...args)); +} + function readFixtureSync(args, enc) { if (Array.isArray(args)) return fs.readFileSync(fixturesPath(...args), enc); @@ -26,6 +31,7 @@ function readFixtureKeys(enc, ...names) { module.exports = { fixturesDir, path: fixturesPath, + fileURL: fixturesFileURL, readSync: readFixtureSync, readKey: readFixtureKey, readKeys: readFixtureKeys, diff --git a/test/common/fixtures.mjs b/test/common/fixtures.mjs index 06564de6fa3b..d6f7f6c092aa 100644 --- a/test/common/fixtures.mjs +++ b/test/common/fixtures.mjs @@ -3,6 +3,7 @@ import fixtures from './fixtures.js'; const { fixturesDir, path, + fileURL, readSync, readKey, } = fixtures; @@ -10,6 +11,7 @@ const { export { fixturesDir, path, + fileURL, readSync, readKey, }; diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index 6d3644d87162..3d2acbc6a9db 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -1,8 +1,7 @@ import '../common/index.mjs'; -import { fixturesDir } from '../common/fixtures.mjs'; +import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; -import { join } from 'path'; import { execPath } from 'process'; const importStatement = @@ -19,7 +18,7 @@ const importStatementMultiline = `import { '--eval', input, ], { - cwd: join(fixturesDir, 'es-module-loaders') + cwd: path('es-module-loaders'), }); let stderr = ''; diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index bfb431ceeb47..62ea1c7089a6 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -1,11 +1,12 @@ import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-json-modules', - './test/fixtures/es-modules/import-json-named-export.mjs', + path('es-modules', 'import-json-named-export.mjs'), ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index c077776ac6bf..d6adb6517833 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -1,4 +1,5 @@ import '../common/index.mjs'; +import { fileURL } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -6,7 +7,7 @@ import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', 'i-dont-exist', - './test/fixtures/print-error-message.js', + fileURL('print-error-message.js').href, ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 24e6ae0f657f..abb983fdcc3f 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -1,4 +1,5 @@ import '../common/index.mjs'; +import { fileURL, path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -7,8 +8,8 @@ const child = spawn(execPath, [ '--no-warnings', '--throw-deprecation', '--experimental-loader', - './test/fixtures/es-module-loaders/hooks-obsolete.mjs', - './test/fixtures/print-error-message.js', + fileURL('es-module-loaders', 'hooks-obsolete.mjs').href, + path('print-error-message.js'), ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 5dd3087d6b99..3c1ca728117e 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,12 +1,13 @@ import '../common/index.mjs'; +import { fileURL } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', - './test/fixtures/es-module-loaders/syntax-error.mjs', - './test/fixtures/print-error-message.js', + fileURL('es-module-loaders', 'syntax-error.mjs').href, + fileURL('print-error-message.js').href, ]); let stderr = ''; diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index 495c085dafe3..f5d7ed4c5fbc 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -20,7 +20,7 @@ import { execPath } from 'process'; '--eval', input, ], { - cwd: fixturesDir + cwd: fixturesDir, }); let stderr = ''; diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index d49b5a329a0a..fd3ca8180a01 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -1,10 +1,11 @@ import '../common/index.mjs'; +import { path } from '../common/fixtures.mjs'; import { ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; const child = spawn(execPath, [ - './test/fixtures/es-module-loaders/syntax-error.mjs', + path('es-module-loaders', 'syntax-error.mjs'), ]); let stderr = ''; From f55caa64325b3c2fca5e6bd30042f81be4a7c384 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Mon, 3 Jan 2022 21:56:54 -0800 Subject: [PATCH 15/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 9 ++++----- test/es-module/test-esm-import-json-named-export.mjs | 8 ++++---- test/es-module/test-esm-loader-not-found.mjs | 8 ++++---- test/es-module/test-esm-loader-obsolete-hooks.mjs | 12 ++++++------ test/es-module/test-esm-loader-with-syntax-error.mjs | 7 ++++--- .../test-esm-module-not-found-commonjs-hint.mjs | 8 ++++---- test/es-module/test-esm-syntax-error.mjs | 4 ++-- 7 files changed, 28 insertions(+), 28 deletions(-) diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index 3d2acbc6a9db..ee9ab421fa84 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -29,10 +29,9 @@ const importStatementMultiline = `import { child.on('close', () => { // SyntaxError: The requested module './module-named-exports.mjs' // does not provide an export named 'notfound' - ok(stderr.includes('SyntaxError:') || console.error(stderr)); + match(stderr, /SyntaxError:/); // The quotes ensure that the path starts with ./ and not ../ - ok(stderr.includes('\'./module-named-exports.mjs\'') || - console.error(stderr)); - ok(stderr.includes('notfound') || console.error(stderr)); + match(stderr, /'\.\/module-named-exports\.mjs'/); + match(stderr, /notfound/); }); }); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index 62ea1c7089a6..1a07f571261b 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -17,7 +17,7 @@ child.stderr.on('data', (data) => { child.on('close', () => { // SyntaxError: The requested module '../experimental.json' // does not provide an export named 'ofLife' - ok(stderr.includes('SyntaxError:') || console.error(stderr)); - ok(stderr.includes('\'../experimental.json\'') || console.error(stderr)); - ok(stderr.includes('\'ofLife\'') || console.error(stderr)); + match(stderr, /SyntaxError:/); + match(stderr, /'\.\.\/experimental\.json'/); + match(stderr, /'ofLife'/); }); diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index d6adb6517833..ba5d40d32130 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { fileURL } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match, ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -18,8 +18,8 @@ child.stderr.on('data', (data) => { child.on('close', () => { // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' // imported from - ok(stderr.includes('ERR_MODULE_NOT_FOUND') || console.error(stderr)); - ok(stderr.includes('\'i-dont-exist\'') || console.error(stderr)); + match(stderr, /ERR_MODULE_NOT_FOUND/); + match(stderr, /'i-dont-exist'/); - ok(!stderr.includes('Bad command or file name') || console.error(stderr)); + ok(!stderr.includes('Bad command or file name')); }); diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index abb983fdcc3f..718189c23400 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { fileURL, path } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -20,9 +20,9 @@ child.stderr.on('data', (data) => { child.on('close', () => { // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: // dynamicInstantiate, getFormat, getSource, transformSource - ok(stderr.includes('DeprecationWarning:') || console.error(stderr)); - ok(stderr.includes('dynamicInstantiate') || console.error(stderr)); - ok(stderr.includes('getFormat') || console.error(stderr)); - ok(stderr.includes('getSource') || console.error(stderr)); - ok(stderr.includes('transformSource') || console.error(stderr)); + match(stderr, /DeprecationWarning:/); + match(stderr, /dynamicInstantiate/); + match(stderr, /getFormat/); + match(stderr, /getSource/); + match(stderr, /transformSource/); }); diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 3c1ca728117e..05cf4e95c963 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { fileURL } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match, ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -16,6 +16,7 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes('SyntaxError:') || console.error(stderr)); - ok(!stderr.includes('Bad command or file name') || console.error(stderr)); + match(stderr, /SyntaxError:/); + + ok(!stderr.includes('Bad command or file name')); }); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index f5d7ed4c5fbc..59f6099aa70c 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { fixturesDir } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -8,11 +8,11 @@ import { execPath } from 'process'; { input: 'import "./print-error-message"', // Did you mean to import ../print-error-message.js? - expected: ' ../print-error-message.js?' + expected: / \.\.\/print-error-message\.js\?/, }, { input: 'import obj from "some_module/obj"', - expected: ' some_module/obj.js?' + expected: / some_module\/obj\.js\?/, }, ].forEach(({ input, expected }) => { const child = spawn(execPath, [ @@ -29,6 +29,6 @@ import { execPath } from 'process'; stderr += data; }); child.on('close', () => { - ok(stderr.includes(expected) || console.error(stderr)); + match(stderr, expected); }); }); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index fd3ca8180a01..b88d6d9dcab0 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -1,6 +1,6 @@ import '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { ok } from 'assert'; +import { match } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -14,5 +14,5 @@ child.stderr.on('data', (data) => { stderr += data; }); child.on('close', () => { - ok(stderr.includes('SyntaxError:') || console.error(stderr)); + match(stderr, /SyntaxError:/); }); From 296489813ab714b36716926f7f3033bb8c2bf0b3 Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Tue, 4 Jan 2022 13:23:07 -0800 Subject: [PATCH 16/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-loader-not-found.mjs | 4 ++-- test/es-module/test-esm-loader-with-syntax-error.mjs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index ba5d40d32130..9efa9cf8fce5 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -1,5 +1,5 @@ import '../common/index.mjs'; -import { fileURL } from '../common/fixtures.mjs'; +import { path } from '../common/fixtures.mjs'; import { match, ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -7,7 +7,7 @@ import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', 'i-dont-exist', - fileURL('print-error-message.js').href, + path('print-error-message.js'), ]); let stderr = ''; diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 05cf4e95c963..82fa14ca5ee2 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,5 +1,5 @@ import '../common/index.mjs'; -import { fileURL } from '../common/fixtures.mjs'; +import { fileURL, path } from '../common/fixtures.mjs'; import { match, ok } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -7,7 +7,7 @@ import { execPath } from 'process'; const child = spawn(execPath, [ '--experimental-loader', fileURL('es-module-loaders', 'syntax-error.mjs').href, - fileURL('print-error-message.js').href, + path('print-error-message.js'), ]); let stderr = ''; From 211db372ffc7e65e084eb74314aa28d8dec53dbc Mon Sep 17 00:00:00 2001 From: Geoffrey Booth Date: Wed, 5 Jan 2022 16:07:57 -0800 Subject: [PATCH 17/17] fixup! esm: refactor esm tests out of test/message --- test/es-module/test-esm-export-not-found.mjs | 10 ++++++---- test/es-module/test-esm-import-json-named-export.mjs | 10 ++++++---- test/es-module/test-esm-loader-not-found.mjs | 10 ++++++---- test/es-module/test-esm-loader-obsolete-hooks.mjs | 10 ++++++---- test/es-module/test-esm-loader-with-syntax-error.mjs | 10 ++++++---- .../test-esm-module-not-found-commonjs-hint.mjs | 9 +++++---- test/es-module/test-esm-syntax-error.mjs | 9 +++++---- 7 files changed, 40 insertions(+), 28 deletions(-) diff --git a/test/es-module/test-esm-export-not-found.mjs b/test/es-module/test-esm-export-not-found.mjs index ee9ab421fa84..cdfe6df0fcde 100644 --- a/test/es-module/test-esm-export-not-found.mjs +++ b/test/es-module/test-esm-export-not-found.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { match } from 'assert'; +import { match, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -26,12 +26,14 @@ const importStatementMultiline = `import { child.stderr.on('data', (data) => { stderr += data; }); - child.on('close', () => { + child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + // SyntaxError: The requested module './module-named-exports.mjs' // does not provide an export named 'notfound' match(stderr, /SyntaxError:/); // The quotes ensure that the path starts with ./ and not ../ match(stderr, /'\.\/module-named-exports\.mjs'/); match(stderr, /notfound/); - }); + })); }); diff --git a/test/es-module/test-esm-import-json-named-export.mjs b/test/es-module/test-esm-import-json-named-export.mjs index 1a07f571261b..f70b927329b6 100644 --- a/test/es-module/test-esm-import-json-named-export.mjs +++ b/test/es-module/test-esm-import-json-named-export.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { match } from 'assert'; +import { match, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -14,10 +14,12 @@ child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { stderr += data; }); -child.on('close', () => { +child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + // SyntaxError: The requested module '../experimental.json' // does not provide an export named 'ofLife' match(stderr, /SyntaxError:/); match(stderr, /'\.\.\/experimental\.json'/); match(stderr, /'ofLife'/); -}); +})); diff --git a/test/es-module/test-esm-loader-not-found.mjs b/test/es-module/test-esm-loader-not-found.mjs index 9efa9cf8fce5..275f0b0f1e85 100644 --- a/test/es-module/test-esm-loader-not-found.mjs +++ b/test/es-module/test-esm-loader-not-found.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { match, ok } from 'assert'; +import { match, ok, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -15,11 +15,13 @@ child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { stderr += data; }); -child.on('close', () => { +child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + // Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'i-dont-exist' // imported from match(stderr, /ERR_MODULE_NOT_FOUND/); match(stderr, /'i-dont-exist'/); ok(!stderr.includes('Bad command or file name')); -}); +})); diff --git a/test/es-module/test-esm-loader-obsolete-hooks.mjs b/test/es-module/test-esm-loader-obsolete-hooks.mjs index 718189c23400..eff4104fc265 100644 --- a/test/es-module/test-esm-loader-obsolete-hooks.mjs +++ b/test/es-module/test-esm-loader-obsolete-hooks.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { fileURL, path } from '../common/fixtures.mjs'; -import { match } from 'assert'; +import { match, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -17,7 +17,9 @@ child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { stderr += data; }); -child.on('close', () => { +child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + // DeprecationWarning: Obsolete loader hook(s) supplied and will be ignored: // dynamicInstantiate, getFormat, getSource, transformSource match(stderr, /DeprecationWarning:/); @@ -25,4 +27,4 @@ child.on('close', () => { match(stderr, /getFormat/); match(stderr, /getSource/); match(stderr, /transformSource/); -}); +})); diff --git a/test/es-module/test-esm-loader-with-syntax-error.mjs b/test/es-module/test-esm-loader-with-syntax-error.mjs index 82fa14ca5ee2..d973e72975e8 100644 --- a/test/es-module/test-esm-loader-with-syntax-error.mjs +++ b/test/es-module/test-esm-loader-with-syntax-error.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { fileURL, path } from '../common/fixtures.mjs'; -import { match, ok } from 'assert'; +import { match, ok, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -15,8 +15,10 @@ child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { stderr += data; }); -child.on('close', () => { +child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); + match(stderr, /SyntaxError:/); ok(!stderr.includes('Bad command or file name')); -}); +})); diff --git a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs index 59f6099aa70c..58f70d0b6853 100644 --- a/test/es-module/test-esm-module-not-found-commonjs-hint.mjs +++ b/test/es-module/test-esm-module-not-found-commonjs-hint.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { fixturesDir } from '../common/fixtures.mjs'; -import { match } from 'assert'; +import { match, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -28,7 +28,8 @@ import { execPath } from 'process'; child.stderr.on('data', (data) => { stderr += data; }); - child.on('close', () => { + child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); match(stderr, expected); - }); + })); }); diff --git a/test/es-module/test-esm-syntax-error.mjs b/test/es-module/test-esm-syntax-error.mjs index b88d6d9dcab0..a8c019171717 100644 --- a/test/es-module/test-esm-syntax-error.mjs +++ b/test/es-module/test-esm-syntax-error.mjs @@ -1,6 +1,6 @@ -import '../common/index.mjs'; +import { mustCall } from '../common/index.mjs'; import { path } from '../common/fixtures.mjs'; -import { match } from 'assert'; +import { match, notStrictEqual } from 'assert'; import { spawn } from 'child_process'; import { execPath } from 'process'; @@ -13,6 +13,7 @@ child.stderr.setEncoding('utf8'); child.stderr.on('data', (data) => { stderr += data; }); -child.on('close', () => { +child.on('close', mustCall((code, _signal) => { + notStrictEqual(code, 0); match(stderr, /SyntaxError:/); -}); +}));