Repository: semantic-release/semantic-release
Pull request #461 (2017-10-06 01:47:31)

Always pass pluginConfig to plugins as a defined object

codecov[bot]: # [Codecov](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=h1) Report
> Merging [#461](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=desc) into [caribou](https://codecov.io/gh/semantic-release/semantic-release/commit/85dd69b3a240a328aeb14d1b9d2282bb70afa36c?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/semantic-release/semantic-release/pull/461/graphs/tree.svg?width=650&height=150&src=pr&token=hENTgPdVFG)](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=tree)

```diff
@@           Coverage Diff            @@
##           caribou     #461   +/-   ##
========================================
  Coverage    87.21%   87.21%           
========================================
  Files           10       10           
  Lines          219      219           
  Branches        47       48    +1     
========================================
  Hits           191      191           
  Misses          18       18           
  Partials        10       10
```


| [Impacted Files](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/lib/plugins.js](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=tree#diff-c3JjL2xpYi9wbHVnaW5zLmpz) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=footer). Last update [85dd69b...87a0303](https://codecov.io/gh/semantic-release/semantic-release/pull/461?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/lib/plugins.js b/src/lib/plugins.js
index d4a6ec8..58831de 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;


Test patch:
diff --git a/test/plugins.test.js b/test/plugins.test.js
index 9a0e052..a1bc66c 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, {});
+});