Repository: infinitered/solidarity
Pull request #99 (2017-10-26 04:23:46)

added support for directory alias of dir
Addresses #95 


Patch:
diff --git a/appveyor.yml b/appveyor.yml
new file mode 100644
index 0000000..32b030a
--- /dev/null
+++ b/appveyor.yml
@@ -0,0 +1,4 @@
+build: off
+
+test:
+  - npm run test:ci
\ No newline at end of file
diff --git a/docs/options.md b/docs/options.md
index 9d105fc..3eaac2c 100644
--- a/docs/options.md
+++ b/docs/options.md
@@ -74,7 +74,7 @@ Lastly, if output has multiple versions, you can identify the index of the versi
 `file` rule means for a given file passed in the `location` property, we will verify it exists.
 
 ### Directory Rules
-`dir` rule means for a given directory passed in the `location` property, we will verify it exists.
+`dir` (or `directory`) rule means for a given directory passed in the `location` property, we will verify it exists.
 
 ### Friendly Errors
 So what do we do if a rule fails?  The return code will be non-zero, but that's not the most friendly option.  You can set the `error` for any rule to give the user legible instruction on why the failure happened, and how they should solve it.
diff --git a/src/extensions/functions/checkRequirement.ts b/src/extensions/functions/checkRequirement.ts
index b34ae4a..fc14c73 100644
--- a/src/extensions/functions/checkRequirement.ts
+++ b/src/extensions/functions/checkRequirement.ts
@@ -67,6 +67,7 @@ module.exports = async (requirement: SolidarityRequirement, context: SolidarityR
           return addFailure(rule.error || `'$${rule.variable}' environment variable not found`)
         }
       // Handle dir rule check
+      case 'directory':
       case 'dir':
         const dirResult = checkDir(rule, context)
         ruleString = `${requirementName} - ${rule.location} directory`
diff --git a/src/index.ts b/src/index.ts
index 74097ae..9a8b60e 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -8,7 +8,8 @@ module.exports = async (): Promise<void> => {
     // local installs
     .plugins('./node_modules', { matching: 'solidarity-*', hidden: true })
     // global installs
-    .plugins('/usr/local/lib/node_modules', { matching: 'solidarity-*', hidden: true })
+    .plugins('/usr/local/lib/node_modules', { matching: 'solidarity-*', hidden: true }) // Darwin
+    .plugins(`${process.env.appdata}/npm/node_modules`, { matching: 'solidarity-*', hidden: true}) // Windows
     // for testing - force load a local plugin
     // .plugin('../solidarity-react-native')
     .create()


Test patch:
diff --git a/__tests__/command_helpers/checkRequirement.ts b/__tests__/command_helpers/checkRequirement.ts
index 9a13a59..7e215f8 100644
--- a/__tests__/command_helpers/checkRequirement.ts
+++ b/__tests__/command_helpers/checkRequirement.ts
@@ -98,6 +98,16 @@ describe('checkRequirement', () => {
       expect(result).toEqual([[]])
     })
 
+    test('directory alias', async () => {
+      checkDir.mockImplementation(() => 'It worked!')
+
+      const rule = toPairs({
+        YARN: [{ rule: 'directory', location: 'yarn' }]
+      })[0]
+      const result = await checkRequirement(rule, context)
+      expect(result).toEqual([[]])
+    })
+
     test('sad path', async () => {
       checkDir.mockImplementation(() => false)
 
@@ -159,12 +169,10 @@ describe('checkRequirement', () => {
 
   describe('when rule fails with custom error messages', () => {
     const customError = 'customError'
-    beforeEach(() => {
-      checkCLI.mockClear()
-      checkCLI.mockImplementation(() => true)
-    })
 
     test('failed CLI rule with custom message', async () => {
+      checkCLI.mockClear()
+      checkCLI.mockImplementation(() => true)
       const rule = toPairs({
         YARN: [{ rule: 'cli', binary: 'gazorpazorp', error: customError }]
       })[0]
diff --git a/__tests__/integration/solidarity-check/check-invalid.ts b/__tests__/integration/solidarity-check/check-invalid.ts
index 343874c..22acf9e 100644
--- a/__tests__/integration/solidarity-check/check-invalid.ts
+++ b/__tests__/integration/solidarity-check/check-invalid.ts
@@ -3,12 +3,22 @@ import tempy from 'tempy'
 
 const SOLIDARITY = `${process.cwd()}/bin/solidarity`
 const origCwd = process.cwd()
+let originalTimeout
 
 beforeAll(() => {
+  // These can be slow on CI
+  originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
+  jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
+  // Tempy!
   const tempDir = tempy.directory()
   process.chdir(tempDir)
 })
 
+afterAll(function () {
+  // Fix timeout change
+  jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
+})
+
 test('default looks for .solidarity file', async done => {
   try {
     await execa(SOLIDARITY)