From 53ae7acd2f07f0aee568bcca4186088ba68f8847 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Thu, 16 Aug 2018 21:01:28 -0500 Subject: [PATCH 1/6] fix version catcher to not snag java --- src/extensions/functions/removeNonVersionCharacters.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/functions/removeNonVersionCharacters.ts b/src/extensions/functions/removeNonVersionCharacters.ts index f734821..234c900 100644 --- a/src/extensions/functions/removeNonVersionCharacters.ts +++ b/src/extensions/functions/removeNonVersionCharacters.ts @@ -1,6 +1,6 @@ import { CLIRule } from '../../types' module.exports = (rule: CLIRule, line: string): string => { - 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 From c215948563751673f1b7fc6b275de69e23c09e21 Mon Sep 17 00:00:00 2001 From: Gant Laborde Date: Thu, 16 Aug 2018 21:23:47 -0500 Subject: [PATCH 2/6] fix stderror on windows --- src/extensions/functions/checkSTDERR.ts | 17 +++++++++++++++++ src/extensions/functions/getVersion.ts | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 src/extensions/functions/checkSTDERR.ts diff --git a/src/extensions/functions/checkSTDERR.ts b/src/extensions/functions/checkSTDERR.ts new file mode 100644 index 0000000..4601552 --- /dev/null +++ b/src/extensions/functions/checkSTDERR.ts @@ -0,0 +1,17 @@ +import { CLIRule, SolidarityRunContext } from '../../types' +import { version } from 'punycode'; +const currentPlatform = process.platform +// Get the version of a specific CLI +module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise => { + const { system } = context + + 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 system.run(`${rule.binary} ${rule.version} ${grabErrorOutput}`) +} diff --git a/src/extensions/functions/getVersion.ts b/src/extensions/functions/getVersion.ts index 985172d..d0f4d99 100644 --- a/src/extensions/functions/getVersion.ts +++ b/src/extensions/functions/getVersion.ts @@ -7,6 +7,11 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise Date: Thu, 16 Aug 2018 21:35:35 -0500 Subject: [PATCH 3/6] clean up unused --- src/extensions/functions/checkSTDERR.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extensions/functions/checkSTDERR.ts b/src/extensions/functions/checkSTDERR.ts index 4601552..6f44514 100644 --- a/src/extensions/functions/checkSTDERR.ts +++ b/src/extensions/functions/checkSTDERR.ts @@ -1,5 +1,5 @@ import { CLIRule, SolidarityRunContext } from '../../types' -import { version } from 'punycode'; + const currentPlatform = process.platform // Get the version of a specific CLI module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise => { From 69ca1fe1f5125c96b1c3e2ffc607a4ed43d39bc3 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 16 Aug 2018 22:14:47 -0500 Subject: [PATCH 4/6] fixup tests --- __tests__/command_helpers/getSolidarityHelpers.ts | 2 +- __tests__/command_helpers/getVersion.ts | 4 ++-- src/extensions/functions/getSolidarityHelpers.ts | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/__tests__/command_helpers/getSolidarityHelpers.ts b/__tests__/command_helpers/getSolidarityHelpers.ts index a3b8d17..0e761e3 100644 --- a/__tests__/command_helpers/getSolidarityHelpers.ts +++ b/__tests__/command_helpers/getSolidarityHelpers.ts @@ -42,7 +42,7 @@ describe('Test helper functions', () => { }) 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/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 From 7f2ba69deda2c5046b5fa0aaa0466c668a5e41f3 Mon Sep 17 00:00:00 2001 From: Gant Date: Thu, 16 Aug 2018 22:34:22 -0500 Subject: [PATCH 5/6] add tests --- __tests__/command_helpers/getSolidarityHelpers.ts | 12 ++++++++++++ src/extensions/functions/checkSTDERR.ts | 12 +++++------- src/extensions/functions/getVersion.ts | 5 +++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/__tests__/command_helpers/getSolidarityHelpers.ts b/__tests__/command_helpers/getSolidarityHelpers.ts index 0e761e3..de5ef3f 100644 --- a/__tests__/command_helpers/getSolidarityHelpers.ts +++ b/__tests__/command_helpers/getSolidarityHelpers.ts @@ -36,7 +36,19 @@ 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() }) diff --git a/src/extensions/functions/checkSTDERR.ts b/src/extensions/functions/checkSTDERR.ts index 6f44514..283b87e 100644 --- a/src/extensions/functions/checkSTDERR.ts +++ b/src/extensions/functions/checkSTDERR.ts @@ -1,10 +1,8 @@ -import { CLIRule, SolidarityRunContext } from '../../types' - -const currentPlatform = process.platform -// Get the version of a specific CLI -module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise => { - const { system } = context +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` @@ -13,5 +11,5 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise Date: Thu, 16 Aug 2018 22:34:22 -0500 Subject: [PATCH 6/6] add tests --- __tests__/command_helpers/checkSTDERR.ts | 13 +++++++++++++ __tests__/command_helpers/getSolidarityHelpers.ts | 12 ++++++++++++ src/extensions/functions/checkSTDERR.ts | 12 +++++------- src/extensions/functions/getVersion.ts | 5 +++-- 4 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 __tests__/command_helpers/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 0e761e3..de5ef3f 100644 --- a/__tests__/command_helpers/getSolidarityHelpers.ts +++ b/__tests__/command_helpers/getSolidarityHelpers.ts @@ -36,7 +36,19 @@ 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() }) diff --git a/src/extensions/functions/checkSTDERR.ts b/src/extensions/functions/checkSTDERR.ts index 6f44514..283b87e 100644 --- a/src/extensions/functions/checkSTDERR.ts +++ b/src/extensions/functions/checkSTDERR.ts @@ -1,10 +1,8 @@ -import { CLIRule, SolidarityRunContext } from '../../types' - -const currentPlatform = process.platform -// Get the version of a specific CLI -module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise => { - const { system } = context +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` @@ -13,5 +11,5 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise