From 31eb84caa4d24f1a753aa9b11d7c56f4399f3a71 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Thu, 16 Aug 2018 20:45:37 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=8D=20Fixup=20java=20python=20(#219)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix version catcher to not snag java * fix stderror on windows * clean up unused * fixup tests * add tests * add tests --- __tests__/command_helpers/checkSTDERR.ts | 13 +++++++++++++ __tests__/command_helpers/getSolidarityHelpers.ts | 14 +++++++++++++- __tests__/command_helpers/getVersion.ts | 4 ++-- src/extensions/functions/checkSTDERR.ts | 15 +++++++++++++++ src/extensions/functions/getSolidarityHelpers.ts | 3 ++- src/extensions/functions/getVersion.ts | 6 ++++++ .../functions/removeNonVersionCharacters.ts | 2 +- 7 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 __tests__/command_helpers/checkSTDERR.ts create mode 100644 src/extensions/functions/checkSTDERR.ts diff --git a/__tests__/command_helpers/checkSTDERR.ts b/__tests__/command_helpers/checkSTDERR.ts new file mode 100644 index 0000000..4ac88a0 --- /dev/null +++ b/__tests__/command_helpers/checkSTDERR.ts @@ -0,0 +1,13 @@ +const checkSTDERR = require('../../src/extensions/functions/checkSTDERR') +const context = require('mockContext') + +describe('checkSTDERR', () => { + test('returns augmented string', async () => { + const rule = { rule: 'cli', binary: 'yarn', version: '--version' } + const normal = `${rule.binary} ${rule.version}` + const output = await checkSTDERR(rule, context) + + expect(typeof output).toBe('string') + expect(output.length).toBeGreaterThan(normal.length) + }) +} diff --git a/__tests__/command_helpers/getSolidarityHelpers.ts b/__tests__/command_helpers/getSolidarityHelpers.ts index a3b8d17..de5ef3f 100644 --- a/__tests__/command_helpers/getSolidarityHelpers.ts +++ b/__tests__/command_helpers/getSolidarityHelpers.ts @@ -36,13 +36,25 @@ describe('Test helper functions', () => { // describe('loadModule', () => { // }) + let originalTimeout describe('loadWebCheck', () => { + beforeAll(() => { + // These can be slow on CI + originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL + jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000 + }) + + afterAll(function() { + // Fix timeout change + jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout + }) + test('loadWebCheck positive cases', async () => { expect(await loadWebCheck(context, 'https://raw.githubusercontent.com/infinitered/solidarity-stacks/master/stacks/react-native.solidarity')).toBeTruthy() }) test('loadWebCheck false cases', async () => { - await expect(loadWebCheck(context, 'https://raw.githubusercontent.com/infinitered/solidarity-stacks/master/stacks/failsauce')) + await expect(loadWebCheck(context, 'https://raw.githubusercontent.com/fail/sauce')) .rejects .toThrow() }) diff --git a/__tests__/command_helpers/getVersion.ts b/__tests__/command_helpers/getVersion.ts index a2ab5a5..b87b103 100644 --- a/__tests__/command_helpers/getVersion.ts +++ b/__tests__/command_helpers/getVersion.ts @@ -35,7 +35,7 @@ describe('getVersion', () => { }) test('throws an error if no version flag works', async () => { - const rule = { rule: 'cli', binary: 'ls' } + const rule = { rule: 'cli', binary: 'cd' } let result try { @@ -43,6 +43,6 @@ describe('getVersion', () => { } catch (e) { result = e } - expect(result).toEqual("No version was detected from the output of the binary 'ls'") + expect(result).toEqual("No version identifier flag for this binary was found") }) }) diff --git a/src/extensions/functions/checkSTDERR.ts b/src/extensions/functions/checkSTDERR.ts new file mode 100644 index 0000000..283b87e --- /dev/null +++ b/src/extensions/functions/checkSTDERR.ts @@ -0,0 +1,15 @@ +import { CLIRule } from '../../types' + +// Creates STDERR catching string +module.exports = (rule: CLIRule): string => { + const currentPlatform = process.platform + let grabErrorOutput: string + if (currentPlatform === 'win32') { + const tempFile = `solidarityWinFix${rule.binary}.tmp` + grabErrorOutput = `1>${tempFile} 2>&1 & type ${tempFile} & del ${tempFile}` + } else { + grabErrorOutput = '2>&1 | cat' + } + + return `${rule.binary} ${rule.version} ${grabErrorOutput}` +} diff --git a/src/extensions/functions/getSolidarityHelpers.ts b/src/extensions/functions/getSolidarityHelpers.ts index 5f8d2d5..8fdced9 100644 --- a/src/extensions/functions/getSolidarityHelpers.ts +++ b/src/extensions/functions/getSolidarityHelpers.ts @@ -38,7 +38,8 @@ export const loadWebCheck = async (context, checkOption) => { const checkSpinner = silentMode || moderateMode ? null : print.spin(`Running check on ${checkOption}`) // the base URL is throw away, and will go away in next version of apisauce const api = http.create({ - baseURL: 'https://api.github.com' + baseURL: 'https://api.github.com', + timeout: 10000 // 10 seconds }) // Load check from web diff --git a/src/extensions/functions/getVersion.ts b/src/extensions/functions/getVersion.ts index 985172d..947b455 100644 --- a/src/extensions/functions/getVersion.ts +++ b/src/extensions/functions/getVersion.ts @@ -7,6 +7,12 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise { - const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9]+\w+)?/g) + const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9|_]+\w+)?/g) if (Array.isArray(foundVersions)) { const matchIndex = rule.matchIndex || 0