Skip to content

Commit 6ebc451

Browse files
authored
✨ Fixups for new version (#180)
* improved integraiton testing ✅ * verified basic commands * testing empty snapshot * handle errors better * fix snapshots to not be machine specific * fixup tests for windows * fixing more stuff for windows * lower bar for tests * handling windows problems right * add ugly output to tests for windows * debugging cli * try lowering number for windows CI * stay in temp dir for test
1 parent 3b0cede commit 6ebc451

File tree

12 files changed

+198
-14
lines changed

12 files changed

+198
-14
lines changed

__tests__/command_helpers/getVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ describe('getVersion', () => {
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 was detected from the output of the binary 'ls'")
4747
})
4848
})

__tests__/command_helpers/removeNonVersionCharacters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test('parse the result', () => {
1313
test('throws an error when there is no version output', () => {
1414
const line = 'Homebrew without versions'
1515
const rule = { binary: 'ls' }
16-
const errorMessage = ` No version was detected from the output of the binary '${rule.binary}'`
16+
const errorMessage = `No version was detected from the output of the binary '${rule.binary}'`
1717
expect(() => {
1818
removeNonVersionCharacters(rule, line)
1919
}).toThrowError(errorMessage)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`also looks for .solidarity.json file 1`] = `
4+
"
5+
✔︎ Solidarity checks valid"
6+
`;
7+
8+
exports[`default looks for .solidarity file 1`] = `
9+
"
10+
✔︎ Solidarity checks valid"
11+
`;
12+
13+
exports[`silent flag works 1`] = `""`;
14+
15+
exports[`verbose flag works 1`] = `
16+
"
17+
✔︎ Solidarity checks valid"
18+
`;

__tests__/integration/solidarity-check/check-invalid.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import execa from 'execa'
22
import tempy from 'tempy'
33

4-
const SOLIDARITY = `${process.cwd()}/bin/solidarity`
4+
const path = require('path')
5+
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
56
const origCwd = process.cwd()
67
let originalTimeout
78

@@ -21,7 +22,7 @@ afterAll(function() {
2122

2223
test('default looks for .solidarity file', async done => {
2324
try {
24-
await execa(SOLIDARITY)
25+
await execa.shellSync(SOLIDARITY)
2526
done.fail()
2627
} catch (err) {
2728
expect(err.code).not.toBe(0)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import execa from 'execa'
2+
import tempy from 'tempy'
3+
4+
const path = require('path')
5+
const filesystem = require('fs-jetpack')
6+
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
7+
const origCwd = process.cwd()
8+
let originalTimeout
9+
10+
beforeAll(() => {
11+
// These can be slow on CI
12+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
13+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
14+
})
15+
16+
afterAll(function() {
17+
// Fix timeout change
18+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
19+
})
20+
21+
test('default looks for .solidarity file', async done => {
22+
const tempDir = tempy.directory()
23+
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
24+
process.chdir(tempDir)
25+
try {
26+
await execa.shell(SOLIDARITY).then(result => {
27+
expect(result.stdout).toMatchSnapshot()
28+
done()
29+
})
30+
} catch (err) {
31+
done.fail()
32+
}
33+
})
34+
35+
test('also looks for .solidarity.json file', async done => {
36+
const tempDir = tempy.directory()
37+
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity.json`)
38+
process.chdir(tempDir)
39+
try {
40+
await execa.shell(SOLIDARITY).then(result => {
41+
expect(result.stdout).toMatchSnapshot()
42+
done()
43+
})
44+
} catch (err) {
45+
done.fail()
46+
}
47+
})
48+
49+
test('verbose flag works', async done => {
50+
const tempDir = tempy.directory()
51+
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
52+
process.chdir(tempDir)
53+
try {
54+
await execa.shell(`${SOLIDARITY} --verbose`).then(result => {
55+
expect(result.stdout).toMatchSnapshot()
56+
done()
57+
})
58+
} catch (err) {
59+
done.fail()
60+
}
61+
})
62+
63+
test('silent flag works', async done => {
64+
const tempDir = tempy.directory()
65+
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
66+
process.chdir(tempDir)
67+
try {
68+
await execa.shell(`${SOLIDARITY} --silent`).then(result => {
69+
expect(result.stdout).toMatchSnapshot()
70+
done()
71+
})
72+
} catch (err) {
73+
done.fail()
74+
}
75+
})
76+
77+
afterEach(() => {
78+
process.chdir(origCwd)
79+
})
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import execa from 'execa'
2+
import tempy from 'tempy'
3+
4+
const path = require('path')
5+
const filesystem = require('fs-jetpack')
6+
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
7+
const origCwd = process.cwd()
8+
let originalTimeout
9+
10+
beforeAll(() => {
11+
// These can be slow on CI
12+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
13+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
14+
const tempDir = tempy.directory()
15+
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
16+
process.chdir(tempDir)
17+
})
18+
19+
afterAll(function() {
20+
// Fix timeout change
21+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
22+
})
23+
24+
test('solidarity report works', async done => {
25+
try {
26+
execa.shell(`${SOLIDARITY} report`).then(result => {
27+
// check a few from the report
28+
expect(result.stdout.includes('OS')).toBeTruthy()
29+
expect(result.stdout.includes('CPU')).toBeTruthy()
30+
expect(result.stdout.includes('Report Info')).toBeTruthy()
31+
expect(result.stdout.includes('node')).toBeTruthy()
32+
expect(result.code).toBe(0)
33+
done()
34+
})
35+
} catch (err) {
36+
done.fail()
37+
}
38+
})
39+
40+
afterEach(() => {
41+
process.chdir(origCwd)
42+
})
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import execa from 'execa'
2+
import tempy from 'tempy'
3+
4+
const path = require('path')
5+
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
6+
const origCwd = process.cwd()
7+
let originalTimeout
8+
9+
beforeAll(() => {
10+
// These can be slow on CI
11+
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
12+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
13+
const tempDir = tempy.directory()
14+
process.chdir(tempDir)
15+
})
16+
17+
afterAll(function() {
18+
// Fix timeout change
19+
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
20+
})
21+
22+
test('solidarity report works', async done => {
23+
try {
24+
execa.shell(`echo n | ${SOLIDARITY} snapshot`).then(result => {
25+
// do not snapshot stdout bc windows bitches
26+
expect(result.stdout.includes('Nothing to do')).toBeTruthy()
27+
expect(result.code).toBe(0)
28+
done()
29+
})
30+
} catch (err) {
31+
done.fail()
32+
}
33+
})
34+
35+
afterEach(() => {
36+
process.chdir(origCwd)
37+
})
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{
22
"requirements": {
33
"NPM": [{ "rule": "cli", "binary": "npm" }],
4-
"Yarn": [{ "rule": "cli", "binary": "yarn", "semver": "^1.0.0", "version": "--version" }],
5-
"Node": [{ "rule": "cli", "binary": "node", "semver": ">=7.6.0", "error": "Upgrade to latest node >= 7.6 please."}],
6-
"TypeScript Active": [
7-
{ "rule": "dir", "location": "./src", "error": "Did you get this code from npm? Try github!" },
8-
{ "rule": "dir", "location": "./dist", "error": "You haven't compiled. Run the build script!" }
9-
]
4+
"Node": [{ "rule": "cli", "binary": "node", "semver": ">=4.6.0", "error": "Upgrade to latest node >= 4.6 please."}]
105
}
116
}

src/extensions/functions/checkCLI.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
1515
// ensure we have valid rule input
1616
if (!semver.validRange(rule.semver)) return `Invalid semver rule ${rule.semver}`
1717

18-
const binaryVersion = await solidarity.getVersion(rule, context)
18+
let binaryVersion
19+
try {
20+
binaryVersion = await solidarity.getVersion(rule, context)
21+
} catch (e) {
22+
return e
23+
}
24+
1925
// pad zeros for any non-semver version systems (rules still work)
2026
let binarySemantic = binaryVersion
2127
while (binarySemantic.split('.').length < 3) {

src/extensions/functions/getVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
1919
try {
2020
versionOutput = await system.run(`${rule.binary} -version`)
2121
} catch (_e) {
22-
throw ' No version identifier flag for this binary was found'
22+
throw 'No version identifier flag for this binary was found'
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)