diff --git a/src/lib/plugins.js b/src/lib/plugins.js index d4a6ec88..58831de8 100644 --- a/src/lib/plugins.js +++ b/src/lib/plugins.js @@ -36,7 +36,7 @@ const normalize = (pluginConfig, fallback) => { return relative(pluginConfig.path).bind(null, pluginConfig); } - return require(fallback).bind(null, pluginConfig); + return require(fallback).bind(null, pluginConfig || {}); }; module.exports.normalize = normalize; diff --git a/test/plugins.test.js b/test/plugins.test.js index 9a0e0521..a1bc66c2 100644 --- a/test/plugins.test.js +++ b/test/plugins.test.js @@ -1,3 +1,4 @@ +import {promisify} from 'util'; import test from 'ava'; import plugins from '../src/lib/plugins'; @@ -69,10 +70,34 @@ test('Normalize and load plugin from object', t => { t.is(typeof plugin, 'function'); }); -test('load from fallback', t => { +test('Load from fallback', t => { // Call the normalize function with a fallback const plugin = plugins.normalize(null, '../lib/plugin-noop'); // Verify the fallback plugin is loaded t.is(typeof plugin, 'function'); }); + +test('Always pass a defined "pluginConfig" for plugin defined with string', async t => { + // Call the normalize function with the path of a plugin that returns its config + const plugin = plugins.normalize('./test/fixtures/plugin-result-config'); + const pluginResult = await promisify(plugin)({}); + + t.deepEqual(pluginResult.pluginConfig, {}); +}); + +test('Always pass a defined "pluginConfig" for plugin defined with path', async t => { + // Call the normalize function with the path of a plugin that returns its config + const plugin = plugins.normalize({path: './test/fixtures/plugin-result-config'}); + const pluginResult = await promisify(plugin)({}); + + t.deepEqual(pluginResult.pluginConfig, {path: './test/fixtures/plugin-result-config'}); +}); + +test('Always pass a defined "pluginConfig" for fallback plugin', async t => { + // Call the normalize function with the path of a plugin that returns its config + const plugin = plugins.normalize(null, '../../test/fixtures/plugin-result-config'); + const pluginResult = await promisify(plugin)({}); + + t.deepEqual(pluginResult.pluginConfig, {}); +});