Repository: infinitered/solidarity
Pull request #197 (2018-04-02 01:28:31)

don't fail on missing check functions
added a test, too.

codecov[bot]: # [Codecov](https://codecov.io/gh/infinitered/solidarity/pull/197?src=pr&el=h1) Report
> Merging [#197](https://codecov.io/gh/infinitered/solidarity/pull/197?src=pr&el=desc) into [master](https://codecov.io/gh/infinitered/solidarity/commit/eb8020df9a1334e305a6be2192454c842167e231?src=pr&el=desc) will **increase** coverage by `0.02%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/infinitered/solidarity/pull/197/graphs/tree.svg?width=650&token=eTjcyCooFB&height=150&src=pr)](https://codecov.io/gh/infinitered/solidarity/pull/197?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #197      +/-   ##
=========================================
+ Coverage   82.07%   82.1%   +0.02%     
=========================================
  Files          33      33              
  Lines         636     637       +1     
  Branches      112     113       +1     
=========================================
+ Hits          522     523       +1     
  Misses         78      78              
  Partials       36      36
```


| [Impacted Files](https://codecov.io/gh/infinitered/solidarity/pull/197?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/extensions/functions/checkRequirement.ts](https://codecov.io/gh/infinitered/solidarity/pull/197/diff?src=pr&el=tree#diff-c3JjL2V4dGVuc2lvbnMvZnVuY3Rpb25zL2NoZWNrUmVxdWlyZW1lbnQudHM=) | `79.74% <100%> (+0.25%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/infinitered/solidarity/pull/197?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/infinitered/solidarity/pull/197?src=pr&el=footer). Last update [eb8020d...99fde4f](https://codecov.io/gh/infinitered/solidarity/pull/197?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/src/extensions/functions/checkRequirement.ts b/src/extensions/functions/checkRequirement.ts
index 7853ca7..1b9b768 100644
--- a/src/extensions/functions/checkRequirement.ts
+++ b/src/extensions/functions/checkRequirement.ts
@@ -119,6 +119,8 @@ module.exports = async (
       case 'custom':
         const customPluginRule = findPluginInfo(rule, context)
         if (customPluginRule.success) {
+          // No check provided, we jet
+          if (!customPluginRule.plugin.check) return []
           const customResult = await customPluginRule.plugin.check(rule, context)
           if (customResult && customResult.pass) {
             return addSuccess(customResult.message)


Test patch:
diff --git a/__tests__/command_helpers/checkRequirementPlugins.ts b/__tests__/command_helpers/checkRequirementPlugins.ts
index a8b96b9..d929b09 100644
--- a/__tests__/command_helpers/checkRequirementPlugins.ts
+++ b/__tests__/command_helpers/checkRequirementPlugins.ts
@@ -20,6 +20,21 @@ describe('checkRequirement Plugins', () => {
     expect(result).toEqual(['Boooo failed check'])
   })
 
+  test('CUSTOM and missing check function OK', async () => {
+    mockContext.addPlugin({
+      name: 'Empty Plugin',
+      description: 'I help test plugins',
+      rules: {
+        emptyDude: {}
+      }
+    })
+    const rule = toPairs({
+      TestRequirement: [{ rule: 'custom', plugin: 'Empty Plugin', name: 'emptyDude' }],
+    })[0]
+    const result = await checkRequirement(rule, mockContext)
+    expect(result).toEqual([[]])
+  })
+
   test('failed to find plugin', async () => {
     const rule = toPairs({
       TestRequirement: [{ rule: 'custom', plugin: 'I do not exist', name: 'checkSecondThing' }],