diff options
author | Juan José Arboleda <soyjuanarbol@gmail.com> | 2019-11-27 20:26:36 -0500 |
---|---|---|
committer | Guy Bedford <guybedford@gmail.com> | 2019-12-04 23:25:10 -0500 |
commit | 81ac3023b3ab082804deda96d65530321d8af448 (patch) | |
tree | 28b6f42ac9701d79b036667f983b92238709271c /test | |
parent | bcd5491219bfd34630d331bdca3c92538a7b0e5e (diff) | |
download | android-node-v8-81ac3023b3ab082804deda96d65530321d8af448.tar.gz android-node-v8-81ac3023b3ab082804deda96d65530321d8af448.tar.bz2 android-node-v8-81ac3023b3ab082804deda96d65530321d8af448.zip |
lib,test: improves ERR_REQUIRE_ESM message
PR-URL: https://github.com/nodejs/node/pull/30694
Fixes: https://github.com/nodejs/node/issues/30599
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/es-module/test-cjs-esm-warn.js | 10 | ||||
-rw-r--r-- | test/es-module/test-esm-type-flag-errors.js | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/test/es-module/test-cjs-esm-warn.js b/test/es-module/test-cjs-esm-warn.js index b1b2e7f434..b800a47d05 100644 --- a/test/es-module/test-cjs-esm-warn.js +++ b/test/es-module/test-cjs-esm-warn.js @@ -26,15 +26,19 @@ child.on('close', common.mustCall((code, signal) => { assert.strictEqual(code, 1); assert.strictEqual(signal, null); - assert.ok(stderr.startsWith(`(node:${child.pid}) Warning: ` + - 'require() of ES modules is not supported.\nrequire() of ' + + assert.ok(stderr.indexOf( + `Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: ${required}` + + '\nrequire() of ES modules is not supported.\nrequire() of ' + `${required} from ${requiring} ` + 'is an ES module file as it is a .js file whose nearest parent ' + 'package.json contains "type": "module" which defines all .js ' + 'files in that package scope as ES modules.\nInstead rename ' + `${basename} to end in .cjs, change the requiring code to use ` + 'import(), or remove "type": "module" from ' + - `${pjson}.\n`)); + `${pjson}.\n`) !== -1); assert.ok(stderr.indexOf( 'Error [ERR_REQUIRE_ESM]: Must use import to load ES Module') !== -1); + + assert.strictEqual( + stderr.match(/Must use import to load ES Module/g).length, 1); })); diff --git a/test/es-module/test-esm-type-flag-errors.js b/test/es-module/test-esm-type-flag-errors.js index 5d19cedd84..e0dedc16ca 100644 --- a/test/es-module/test-esm-type-flag-errors.js +++ b/test/es-module/test-esm-type-flag-errors.js @@ -27,7 +27,10 @@ try { require('../fixtures/es-modules/package-type-module/index.js'); assert.fail('Expected CJS to fail loading from type: module package.'); } catch (e) { - assert(e.toString().match(/Error \[ERR_REQUIRE_ESM\]: Must use import to load ES Module:/)); + assert.strictEqual(e.name, 'Error'); + assert.strictEqual(e.code, 'ERR_REQUIRE_ESM'); + assert(e.toString().match(/Must use import to load ES Module/g)); + assert(e.message.match(/Must use import to load ES Module/g)); } function expect(opt = '', inputFile, want, wantsError = false) { |