Repository: infinitered/solidarity
Pull request #131 (2017-11-20 04:13:04)

Attempt to improve test coverage
very small test coverage boost... still trying to figure out some of these gaps.

codecov[bot]: # [Codecov](https://codecov.io/gh/infinitered/solidarity/pull/131?src=pr&el=h1) Report
> Merging [#131](https://codecov.io/gh/infinitered/solidarity/pull/131?src=pr&el=desc) into [master](https://codecov.io/gh/infinitered/solidarity/commit/9cf2c93a4b9c48d35c1f3fb67fcc08bd707b5842?src=pr&el=desc) will **decrease** coverage by `0.25%`.
> The diff coverage is `51.31%`.

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

```diff
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
- Coverage   75.83%   75.58%   -0.26%     
==========================================
  Files          22       22              
  Lines         389      385       -4     
  Branches       73       71       -2     
==========================================
- Hits          295      291       -4     
  Misses         68       68              
  Partials       26       26
```


| [Impacted Files](https://codecov.io/gh/infinitered/solidarity/pull/131?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/commands/solidarity.ts](https://codecov.io/gh/infinitered/solidarity/pull/131?src=pr&el=tree#diff-c3JjL2NvbW1hbmRzL3NvbGlkYXJpdHkudHM=) | `52.94% <51.28%> (-1.78%)` | :arrow_down: |
| [src/commands/snapshot.ts](https://codecov.io/gh/infinitered/solidarity/pull/131?src=pr&el=tree#diff-c3JjL2NvbW1hbmRzL3NuYXBzaG90LnRz) | `53.33% <51.35%> (-1.99%)` | :arrow_down: |

------

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


Patch:
diff --git a/src/commands/snapshot.ts b/src/commands/snapshot.ts
index 17a106e..8ac71d7 100644
--- a/src/commands/snapshot.ts
+++ b/src/commands/snapshot.ts
@@ -51,13 +51,10 @@ namespace Snapshot {
       }
     } else {
       print.error(`No solidarity plugins found!
-
       Add a plugin for a given technology:
       ${print.colors.blue('https://github.com/infinitered/solidarity/blob/master/docs/pluginsList.md')}
-
       OR write your own plugin for generating rules:
       ${print.colors.blue('https://github.com/infinitered/solidarity/blob/master/docs/plugins.md')}
-
       OR simply create a .solidarity rule-set by hand for this project:
       ${print.colors.blue('https://github.com/infinitered/solidarity/blob/master/docs/options.md')}
       `)
diff --git a/src/extensions/functions/checkCLIForUpdates.ts b/src/extensions/functions/checkCLIForUpdates.ts
index 9ddc31d..a24a6fe 100644
--- a/src/extensions/functions/checkCLIForUpdates.ts
+++ b/src/extensions/functions/checkCLIForUpdates.ts
@@ -1,7 +1,7 @@
 import { SolidarityRule, SolidarityRunContext } from '../../types'
+
 module.exports = async (rule: SolidarityRule, context: SolidarityRunContext): Promise<string | undefined> => {
   const { system, semver, solidarity, print } = context
-  const { color } = print
 
   // If binary is set but not found
   if (rule.binary) {
@@ -21,6 +21,6 @@ module.exports = async (rule: SolidarityRule, context: SolidarityRunContext): Pr
   // if it doesn't satisfy, upgrade
   if (rule.semver && !semver.satisfies(binarySemantic, rule.semver)) {
     rule.semver = binaryVersion
-    return color.green(`Setting ${rule.binary} to '${binaryVersion}'`)
+    return print.color.green(`Setting ${rule.binary} to '${binaryVersion}'`)
   }
 }


Test patch:
diff --git a/__tests__/command_helpers/__snapshots__/getSolidaritySettings.ts.snap b/__tests__/command_helpers/__snapshots__/getSolidaritySettings.ts.snap
index 353117f..212f2fd 100644
--- a/__tests__/command_helpers/__snapshots__/getSolidaritySettings.ts.snap
+++ b/__tests__/command_helpers/__snapshots__/getSolidaritySettings.ts.snap
@@ -1,3 +1,3 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`getSolidaritySettings w/ .solidarity getSolidaritySettings exists 1`] = `[Function]`;
+exports[`getSolidaritySettings w/ success getSolidaritySettings exists 1`] = `[Function]`;
diff --git a/__tests__/command_helpers/checkCLIForUpdates.ts b/__tests__/command_helpers/checkCLIForUpdates.ts
index 61d3b8e..3021acc 100644
--- a/__tests__/command_helpers/checkCLIForUpdates.ts
+++ b/__tests__/command_helpers/checkCLIForUpdates.ts
@@ -38,6 +38,7 @@ describe('checkCLIForUpdates', () => {
 
       const result = await checkCLIForUpdates(rule, context)
       expect(result).toEqual("Setting yarn to '1.0'")
+      expect(context.print.color.green).toHaveBeenCalled()
     })
 
     it('does nothing if there was no original semver', async () => {
diff --git a/__tests__/command_helpers/getSolidaritySettings.ts b/__tests__/command_helpers/getSolidaritySettings.ts
index 0fc9f49..f225153 100644
--- a/__tests__/command_helpers/getSolidaritySettings.ts
+++ b/__tests__/command_helpers/getSolidaritySettings.ts
@@ -4,16 +4,24 @@ import getSolidaritySettings from '../../src/extensions/functions/getSolidarityS
 const context = require('gluegun')
 
 describe('getSolidaritySettings', () => {
-  describe('w/ .solidarity', () => {
+  describe('w/ success', () => {
     test('getSolidaritySettings exists', () => expect(getSolidaritySettings).toMatchSnapshot())
-    
+
+    test('getSolidaritySettings succeeds', async () => {
+      const resultSettings = getSolidaritySettings(context)
+      // we got an object with requirements defined
+      expect(resultSettings).toMatchObject({requirements: {}})
+    })
+
     test('getSolidaritySettings succeeds', async () => {
+      process.chdir('__tests__/sandbox/solidarity_json')
       const resultSettings = getSolidaritySettings(context)
       // we got an object with requirements defined
       expect(resultSettings).toMatchObject({requirements: {}})
+      process.chdir('../../../')
     })
   })
-  
+
   test('getSolidaritySettings can fail', async () => {
     expect(() => {
       process.chdir('__tests__')
@@ -21,5 +29,12 @@ describe('getSolidaritySettings', () => {
     }).toThrow()
     process.chdir('../')
   })
-})
 
+  test('getSolidaritySettings can warn with missing requirements', async () => {
+    expect(() => {
+      process.chdir('__tests__/sandbox/solidarity_broken')
+      const resultSettings = getSolidaritySettings(context)
+    }).toThrowError('ERROR: Found, but no requirements key.  Please validate your solidarity file')
+    process.chdir('../../../')
+  })
+})
diff --git a/__tests__/sandbox/solidarity_broken/.solidarity b/__tests__/sandbox/solidarity_broken/.solidarity
new file mode 100644
index 0000000..2c63c08
--- /dev/null
+++ b/__tests__/sandbox/solidarity_broken/.solidarity
@@ -0,0 +1,2 @@
+{
+}
diff --git a/__tests__/sandbox/solidarity_json/.solidarity.json b/__tests__/sandbox/solidarity_json/.solidarity.json
new file mode 100644
index 0000000..c46d251
--- /dev/null
+++ b/__tests__/sandbox/solidarity_json/.solidarity.json
@@ -0,0 +1,11 @@
+{
+  "requirements": {
+    "NPM": [{ "rule": "cli", "binary": "npm" }],
+    "Yarn": [{ "rule": "cli", "binary": "yarn", "semver": "^1.0.0", "version": "--version" }],
+    "Node": [{ "rule": "cli", "binary": "node", "semver": ">=7.6.0", "error": "Upgrade to latest node >= 7.6 please."}],
+    "TypeScript Active": [
+      { "rule": "dir", "location": "./src", "error": "Did you get this code from npm? Try github!" },
+      { "rule": "dir", "location": "./dist", "error": "You haven't compiled. Run the build script!" }
+    ]
+  }
+}