From 9d6a5805855fd813d37bc1dfe11b90552f48fe96 Mon Sep 17 00:00:00 2001 From: Andrew Hyndman Date: Wed, 9 Feb 2022 15:48:53 -0800 Subject: [PATCH] Add unit tests distinguishing modulePaths from moduleDirectories --- .../test/fixtures/custom-module-path/main.js | 3 ++ .../package-with-dependency/main.js | 3 ++ .../node_modules/dependency/main.js | 1 + .../node_modules/dependency/package.json | 3 ++ .../package-with-dependency/package.json | 3 ++ packages/node-resolve/test/test.js | 30 +++++++++++++++++++ 6 files changed, 43 insertions(+) create mode 100644 packages/node-resolve/test/fixtures/custom-module-path/main.js create mode 100644 packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/main.js create mode 100644 packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/main.js create mode 100644 packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/package.json create mode 100644 packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/package.json diff --git a/packages/node-resolve/test/fixtures/custom-module-path/main.js b/packages/node-resolve/test/fixtures/custom-module-path/main.js new file mode 100644 index 000000000..0bf020d0b --- /dev/null +++ b/packages/node-resolve/test/fixtures/custom-module-path/main.js @@ -0,0 +1,3 @@ +import PACKAGE, {dependency} from 'package-with-dependency'; + +export { PACKAGE, dependency }; diff --git a/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/main.js b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/main.js new file mode 100644 index 000000000..3b8eea697 --- /dev/null +++ b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/main.js @@ -0,0 +1,3 @@ +export { dependency } from 'dependency'; + +export default 'PACKAGE_WITH_DEPENDENCY'; diff --git a/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/main.js b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/main.js new file mode 100644 index 000000000..65a4dacab --- /dev/null +++ b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/main.js @@ -0,0 +1 @@ +export const dependency = 'DEPENDENCY'; diff --git a/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/package.json b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/package.json new file mode 100644 index 000000000..daef9fcad --- /dev/null +++ b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/node_modules/dependency/package.json @@ -0,0 +1,3 @@ +{ + "main": "main.js" +} diff --git a/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/package.json b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/package.json new file mode 100644 index 000000000..daef9fcad --- /dev/null +++ b/packages/node-resolve/test/fixtures/custom-module-path/node_modules/package-with-dependency/package.json @@ -0,0 +1,3 @@ +{ + "main": "main.js" +} diff --git a/packages/node-resolve/test/test.js b/packages/node-resolve/test/test.js index 0979eb76a..28001d013 100755 --- a/packages/node-resolve/test/test.js +++ b/packages/node-resolve/test/test.js @@ -257,6 +257,36 @@ test('allows custom moduleDirectories with legacy customResolveOptions.moduleDir t.snapshot(warnings); }); +test('custom moduleDirectories do not support nested dependencies', async (t) => { + const warnings = []; + const bundle = await rollup({ + input: 'custom-module-path/main.js', + onwarn: (warning) => warnings.push(warning), + plugins: [ + nodeResolve({ + moduleDirectories: [join(process.cwd(), 'custom-module-path/node_modules')] + }) + ] + }); + + t.is(warnings.length, 1); + t.is(bundle.cache.modules.length, 2); +}); + +test('allows custom modulePaths', async (t) => { + const bundle = await rollup({ + input: 'custom-module-path/main.js', + onwarn: failOnWarn(t), + plugins: [ + nodeResolve({ + modulePaths: [join(process.cwd(), 'custom-module-path/node_modules')] + }) + ] + }); + + t.is(bundle.cache.modules.length, 3); +}); + test('ignores deep-import non-modules', async (t) => { const warnings = []; const bundle = await rollup({