fix: Always pass pluginConfig to plugins as a defined object
This commit is contained in:
parent
90417c6ffe
commit
8e9d9f77f3
@ -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;
|
||||
|
@ -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, {});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user