From b31b0f250ce3fdc64df3a21d81db761e46b6b560 Mon Sep 17 00:00:00 2001 From: Ralph Huwiler Date: Mon, 27 Nov 2017 18:00:23 +0100 Subject: [PATCH] fixed modulesDir is not initialized with correct default value (#2258) --- lib/common/options.js | 8 ++++---- test/basic.config.defaults.test.js | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 test/basic.config.defaults.test.js diff --git a/lib/common/options.js b/lib/common/options.js index 043024384f..09648b659b 100755 --- a/lib/common/options.js +++ b/lib/common/options.js @@ -43,13 +43,13 @@ Options.from = function (_options) { options.cacheDir = resolve(options.rootDir, options.cacheDir) // Normalize modulesDir + /* istanbul ignore if */ + if (!options.modulesDir) { + options.modulesDir = ['node_modules'] + } if (!Array.isArray(options.modulesDir)) { options.modulesDir = [options.modulesDir] } - /* istanbul ignore if */ - if (!options.modulesDir.length) { - options.modulesDir = ['node_modules'] - } options.modulesDir = options.modulesDir.filter(dir => hasValue(dir)).map(dir => resolve(options.rootDir, dir)) // If app.html is defined, set the template path to the user template diff --git a/test/basic.config.defaults.test.js b/test/basic.config.defaults.test.js new file mode 100644 index 0000000000..e0a14ed0a8 --- /dev/null +++ b/test/basic.config.defaults.test.js @@ -0,0 +1,9 @@ +import test from 'ava' +import { resolve } from 'path' +import { Options } from '../index' + +test('modulesDir uses /node_modules as default if not set', async t => { + const options = Options.from({}) + const currentNodeModulesDir = resolve(__dirname, '..', 'node_modules') + t.true(options.modulesDir.includes(currentNodeModulesDir)) +})