diff options
author | Ali Ijaz Sheikh <ofrobots@google.com> | 2019-02-13 13:21:10 -0800 |
---|---|---|
committer | Ali Ijaz Sheikh <ofrobots@google.com> | 2019-02-15 12:52:05 -0800 |
commit | a02e3e2d5f1f96f3c408270d45935afdd5d1fffc (patch) | |
tree | a279b109ed4c805a03396a1200fa14f62c6f13e0 /test/parallel | |
parent | 05cd1a0929441943ba2d90c210c2d8bd8560293f (diff) | |
download | node-new-a02e3e2d5f1f96f3c408270d45935afdd5d1fffc.tar.gz |
lib: improve error message for MODULE_NOT_FOUND
Include the require stack in the reported error message.
PR-URL: https://github.com/nodejs/node/pull/25690
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel')
-rw-r--r-- | test/parallel/test-internal-modules.js | 2 | ||||
-rw-r--r-- | test/parallel/test-loaders-hidden-from-users.js | 4 | ||||
-rw-r--r-- | test/parallel/test-module-loading-error.js | 7 | ||||
-rw-r--r-- | test/parallel/test-module-multi-extensions.js | 6 | ||||
-rw-r--r-- | test/parallel/test-repl.js | 2 |
5 files changed, 12 insertions, 9 deletions
diff --git a/test/parallel/test-internal-modules.js b/test/parallel/test-internal-modules.js index c61d957acd..e6bd0c9e14 100644 --- a/test/parallel/test-internal-modules.js +++ b/test/parallel/test-internal-modules.js @@ -5,7 +5,7 @@ const assert = require('assert'); assert.throws(function() { require('internal/freelist'); -}, /^Error: Cannot find module 'internal\/freelist'$/); +}, /^Error: Cannot find module 'internal\/freelist'/); assert.strictEqual( require(fixtures.path('internal-modules')), diff --git a/test/parallel/test-loaders-hidden-from-users.js b/test/parallel/test-loaders-hidden-from-users.js index 0d752f5718..104681bd79 100644 --- a/test/parallel/test-loaders-hidden-from-users.js +++ b/test/parallel/test-loaders-hidden-from-users.js @@ -9,7 +9,7 @@ common.expectsError( require('internal/bootstrap/loaders'); }, { code: 'MODULE_NOT_FOUND', - message: 'Cannot find module \'internal/bootstrap/loaders\'' + message: /Cannot find module 'internal\/bootstrap\/loaders'/ } ); @@ -20,6 +20,6 @@ common.expectsError( require('owo'); }, { code: 'MODULE_NOT_FOUND', - message: 'Cannot find module \'owo\'' + message: /Cannot find module 'owo'/ } ); diff --git a/test/parallel/test-module-loading-error.js b/test/parallel/test-module-loading-error.js index 67dee6a3ba..40b6de72a3 100644 --- a/test/parallel/test-module-loading-error.js +++ b/test/parallel/test-module-loading-error.js @@ -80,9 +80,10 @@ common.expectsError( message: 'The argument \'id\' must be a non-empty string. Received \'\'' }); -common.expectsError( +assert.throws( () => { require('../fixtures/packages/is-dir'); }, { code: 'MODULE_NOT_FOUND', - message: 'Cannot find module \'../fixtures/packages/is-dir\'' - }); + message: /Cannot find module '\.\.\/fixtures\/packages\/is-dir'/ + } +); diff --git a/test/parallel/test-module-multi-extensions.js b/test/parallel/test-module-multi-extensions.js index be17bc5d02..1257854115 100644 --- a/test/parallel/test-module-multi-extensions.js +++ b/test/parallel/test-module-multi-extensions.js @@ -35,7 +35,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8'); require(modulePath); assert.throws( () => require(`${modulePath}.foo`), - new Error(`Cannot find module '${modulePath}.foo'`) + (err) => err.message.startsWith(`Cannot find module '${modulePath}.foo'`) ); require(`${modulePath}.foo.bar`); delete require.cache[file]; @@ -47,7 +47,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8'); const modulePath = path.join(tmpdir.path, 'test-extensions'); assert.throws( () => require(modulePath), - new Error(`Cannot find module '${modulePath}'`) + (err) => err.message.startsWith(`Cannot find module '${modulePath}'`) ); delete require.cache[file]; Module._pathCache = Object.create(null); @@ -69,7 +69,7 @@ fs.writeFileSync(dotfileWithExtension, 'console.log(__filename);', 'utf8'); const modulePath = path.join(tmpdir.path, 'test-extensions.foo'); assert.throws( () => require(modulePath), - new Error(`Cannot find module '${modulePath}'`) + (err) => err.message.startsWith(`Cannot find module '${modulePath}'`) ); delete require.extensions['.foo.bar']; Module._pathCache = Object.create(null); diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 14ada1fe60..a53f4a2833 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -534,6 +534,8 @@ const errorTests = [ expect: [ 'Thrown:', /^{ Error: Cannot find module 'internal\/repl'/, + /^Require stack:/, + /^- <repl>/, /^ at .*/, /^ at .*/, /^ at .*/, |