summaryrefslogtreecommitdiff
path: root/test/sequential/test-module-loading.js
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2019-03-20 17:00:57 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-27 17:11:53 +0100
commit115f0f5a57f50f6b039f28a56910207f92df116d (patch)
treeb8937769e8c49b2a51b4ed7772e6bafc2657a14a /test/sequential/test-module-loading.js
parent7bddfcc61a5a7d04583a8c4fec462ca5ce45b677 (diff)
downloadandroid-node-v8-115f0f5a57f50f6b039f28a56910207f92df116d.tar.gz
android-node-v8-115f0f5a57f50f6b039f28a56910207f92df116d.tar.bz2
android-node-v8-115f0f5a57f50f6b039f28a56910207f92df116d.zip
module: throw an error for invalid package.json main entries
We currently ignore invalid `main` entries in package.json files. This does not seem to be very user friendly as it's certainly an error if the `main` entry is not a valid file name. So instead of trying to resolve the file otherwise, throw an error immediately to improve the user experience. To keep it backwards compatible `index.js` files in the same directory as the `package.json` will continue to be resolved instead but that behavior is now deprecated. PR-URL: https://github.com/nodejs/node/pull/26823 Fixes: https://github.com/nodejs/node/issues/26588 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/sequential/test-module-loading.js')
-rw-r--r--test/sequential/test-module-loading.js11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/sequential/test-module-loading.js b/test/sequential/test-module-loading.js
index 0269445c76..630830f5dd 100644
--- a/test/sequential/test-module-loading.js
+++ b/test/sequential/test-module-loading.js
@@ -29,6 +29,8 @@ const path = require('path');
const backslash = /\\/g;
+process.on('warning', common.mustNotCall());
+
console.error('load test-module-loading.js');
assert.strictEqual(require.main.id, '.');
@@ -105,6 +107,15 @@ assert.strictEqual(require('../fixtures/packages/index').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/main-index').ok, 'ok');
assert.strictEqual(require('../fixtures/packages/missing-main').ok, 'ok');
+assert.throws(
+ () => require('../fixtures/packages/missing-main-no-index'),
+ {
+ code: 'MODULE_NOT_FOUND',
+ message: /packages[/\\]missing-main-no-index[/\\]doesnotexist\.js'\. Please.+package\.json.+valid "main"/,
+ path: /fixtures[/\\]packages[/\\]missing-main-no-index[/\\]package\.json/,
+ requestPath: /^\.\.[/\\]fixtures[/\\]packages[/\\]missing-main-no-index$/
+ }
+);
assert.throws(
function() { require('../fixtures/packages/unparseable'); },