From f93eeb799bf6f230be7bdeb1bd6540a8d312a775 Mon Sep 17 00:00:00 2001 From: Pierre Vanduynslager Date: Fri, 6 Jul 2018 23:31:53 -0400 Subject: [PATCH] fix: do not set `path` to plugin config defined as a Function or an Array If a plugin hook was defined as a `Function` or an `Array` the `path` property would be set to the default value. Even if this bug had no actual negative impact, it should be fixed so the code would perform as intended. --- lib/plugins/index.js | 4 ++-- test/plugins/plugins.test.js | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/plugins/index.js b/lib/plugins/index.js index 133fa9ba4a..877dcdd699 100644 --- a/lib/plugins/index.js +++ b/lib/plugins/index.js @@ -1,4 +1,4 @@ -const {isArray, isObject, omit, castArray, isUndefined} = require('lodash'); +const {isPlainObject, omit, castArray, isUndefined} = require('lodash'); const AggregateError = require('aggregate-error'); const getError = require('../get-error'); const PLUGINS_DEFINITIONS = require('../definitions/plugins'); @@ -15,7 +15,7 @@ module.exports = (options, pluginsPath, logger) => { pluginConfs = def; } else { // If an object is passed and the path is missing, set the default one for single plugins - if (isObject(options[pluginType]) && !options[pluginType].path && !isArray(def)) { + if (isPlainObject(options[pluginType]) && !options[pluginType].path && castArray(def).length === 1) { options[pluginType].path = def; } if (config && !config.validator(options[pluginType])) { diff --git a/test/plugins/plugins.test.js b/test/plugins/plugins.test.js index c81214e625..f67367d418 100644 --- a/test/plugins/plugins.test.js +++ b/test/plugins/plugins.test.js @@ -116,11 +116,20 @@ test.serial('Export plugins loaded from the dependency of a shareable config fil }); test('Use default when only options are passed for a single plugin', t => { - const plugins = getPlugins({generateNotes: {}, analyzeCommits: {}}, {}, t.context.logger); + const analyzeCommits = {}; + const success = () => {}; + const fail = [() => {}]; + + const plugins = getPlugins({analyzeCommits, success, fail}, {}, t.context.logger); // Verify the module returns a function for each plugin - t.is(typeof plugins.generateNotes, 'function'); t.is(typeof plugins.analyzeCommits, 'function'); + t.is(typeof plugins.success, 'function'); + t.is(typeof plugins.fail, 'function'); + + // Verify only the plugins defined as an object with no `path` are set to the default value + t.falsy(success.path); + t.falsy(fail.path); }); test('Merge global options with plugin options', async t => {