Skip to content
2 changes: 1 addition & 1 deletion __tests__/command_helpers/getVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 was detected from the output of the binary 'ls'")
})
})
2 changes: 1 addition & 1 deletion __tests__/command_helpers/removeNonVersionCharacters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('parse the result', () => {
test('throws an error when there is no version output', () => {
const line = 'Homebrew without versions'
const rule = { binary: 'ls' }
const errorMessage = ` No version was detected from the output of the binary '${rule.binary}'`
const errorMessage = `No version was detected from the output of the binary '${rule.binary}'`
expect(() => {
removeNonVersionCharacters(rule, line)
}).toThrowError(errorMessage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`also looks for .solidarity.json file 1`] = `
"
✔︎ Solidarity checks valid"
`;

exports[`default looks for .solidarity file 1`] = `
"
✔︎ Solidarity checks valid"
`;

exports[`silent flag works 1`] = `""`;

exports[`verbose flag works 1`] = `
"
✔︎ Solidarity checks valid"
`;
5 changes: 3 additions & 2 deletions __tests__/integration/solidarity-check/check-invalid.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import execa from 'execa'
import tempy from 'tempy'

const SOLIDARITY = `${process.cwd()}/bin/solidarity`
const path = require('path')
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
const origCwd = process.cwd()
let originalTimeout

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

test('default looks for .solidarity file', async done => {
try {
await execa(SOLIDARITY)
await execa.shellSync(SOLIDARITY)
done.fail()
} catch (err) {
expect(err.code).not.toBe(0)
Expand Down
79 changes: 79 additions & 0 deletions __tests__/integration/solidarity-check/check-valid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import execa from 'execa'
import tempy from 'tempy'

const path = require('path')
const filesystem = require('fs-jetpack')
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
const origCwd = process.cwd()
let originalTimeout

beforeAll(() => {
// These can be slow on CI
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
})

afterAll(function() {
// Fix timeout change
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
})

test('default looks for .solidarity file', async done => {
const tempDir = tempy.directory()
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
process.chdir(tempDir)
try {
await execa.shell(SOLIDARITY).then(result => {
expect(result.stdout).toMatchSnapshot()
done()
})
} catch (err) {
done.fail()
}
})

test('also looks for .solidarity.json file', async done => {
const tempDir = tempy.directory()
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity.json`)
process.chdir(tempDir)
try {
await execa.shell(SOLIDARITY).then(result => {
expect(result.stdout).toMatchSnapshot()
done()
})
} catch (err) {
done.fail()
}
})

test('verbose flag works', async done => {
const tempDir = tempy.directory()
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
process.chdir(tempDir)
try {
await execa.shell(`${SOLIDARITY} --verbose`).then(result => {
expect(result.stdout).toMatchSnapshot()
done()
})
} catch (err) {
done.fail()
}
})

test('silent flag works', async done => {
const tempDir = tempy.directory()
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
process.chdir(tempDir)
try {
await execa.shell(`${SOLIDARITY} --silent`).then(result => {
expect(result.stdout).toMatchSnapshot()
done()
})
} catch (err) {
done.fail()
}
})

afterEach(() => {
process.chdir(origCwd)
})
42 changes: 42 additions & 0 deletions __tests__/integration/solidarity-report/report-basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import execa from 'execa'
import tempy from 'tempy'

const path = require('path')
const filesystem = require('fs-jetpack')
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
const origCwd = process.cwd()
let originalTimeout

beforeAll(() => {
// These can be slow on CI
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
const tempDir = tempy.directory()
filesystem.copy(`__tests__${path.sep}sandbox${path.sep}solidarity_json${path.sep}.solidarity.json`, `${tempDir}${path.sep}.solidarity`)
process.chdir(tempDir)
})

afterAll(function() {
// Fix timeout change
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
})

test('solidarity report works', async done => {
try {
execa.shell(`${SOLIDARITY} report`).then(result => {
// check a few from the report
expect(result.stdout.includes('OS')).toBeTruthy()
expect(result.stdout.includes('CPU')).toBeTruthy()
expect(result.stdout.includes('Report Info')).toBeTruthy()
expect(result.stdout.includes('node')).toBeTruthy()
expect(result.code).toBe(0)
done()
})
} catch (err) {
done.fail()
}
})

afterEach(() => {
process.chdir(origCwd)
})
37 changes: 37 additions & 0 deletions __tests__/integration/solidarity-snapshot/snapshot-nada.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import execa from 'execa'
import tempy from 'tempy'

const path = require('path')
const SOLIDARITY = `node ${process.cwd()}${path.sep}bin${path.sep}solidarity`
const origCwd = process.cwd()
let originalTimeout

beforeAll(() => {
// These can be slow on CI
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL
jasmine.DEFAULT_TIMEOUT_INTERVAL = 90000
const tempDir = tempy.directory()
process.chdir(tempDir)
})

afterAll(function() {
// Fix timeout change
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout
})

test('solidarity report works', async done => {
try {
execa.shell(`echo n | ${SOLIDARITY} snapshot`).then(result => {
// do not snapshot stdout bc windows bitches
expect(result.stdout.includes('Nothing to do')).toBeTruthy()
expect(result.code).toBe(0)
done()
})
} catch (err) {
done.fail()
}
})

afterEach(() => {
process.chdir(origCwd)
})
7 changes: 1 addition & 6 deletions __tests__/sandbox/solidarity_json/.solidarity.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{
"requirements": {
"NPM": [{ "rule": "cli", "binary": "npm" }],
"Yarn": [{ "rule": "cli", "binary": "yarn", "semver": "^1.0.0", "version": "--version" }],
"Node": [{ "rule": "cli", "binary": "node", "semver": ">=7.6.0", "error": "Upgrade to latest node >= 7.6 please."}],
"TypeScript Active": [
{ "rule": "dir", "location": "./src", "error": "Did you get this code from npm? Try github!" },
{ "rule": "dir", "location": "./dist", "error": "You haven't compiled. Run the build script!" }
]
"Node": [{ "rule": "cli", "binary": "node", "semver": ">=4.6.0", "error": "Upgrade to latest node >= 4.6 please."}]
}
}
8 changes: 7 additions & 1 deletion src/extensions/functions/checkCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
// ensure we have valid rule input
if (!semver.validRange(rule.semver)) return `Invalid semver rule ${rule.semver}`

const binaryVersion = await solidarity.getVersion(rule, context)
let binaryVersion
try {
binaryVersion = await solidarity.getVersion(rule, context)
} catch (e) {
return e
}

// pad zeros for any non-semver version systems (rules still work)
let binarySemantic = binaryVersion
while (binarySemantic.split('.').length < 3) {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/functions/getVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = async (rule: CLIRule, context: SolidarityRunContext): Promise<s
try {
versionOutput = await system.run(`${rule.binary} -version`)
} catch (_e) {
throw ' No version identifier flag for this binary was found'
throw 'No version identifier flag for this binary was found'
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/functions/removeNonVersionCharacters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = (rule: CLIRule, line: string): string => {
const matchIndex = rule.matchIndex || 0
return foundVersions[matchIndex]
} else {
throw ` No version was detected from the output of the binary '${rule.binary}'`
throw `No version was detected from the output of the binary '${rule.binary}'`
}
}
8 changes: 7 additions & 1 deletion src/extensions/functions/updateRequirement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ module.exports = async (
// Handle CLI rule update
case 'cli':
if (!rule.semver) return []
const updateResult = await checkCLIForUpdates(rule, context)
let updateResult
try {
updateResult = await checkCLIForUpdates(rule, context)
} catch (e) {
spinner.fail(e)
return []
}
const lineMessage = rule.line ? ` line ${rule.line} at` : ''
ruleString = `Keep ${rule.binary}${lineMessage} ${rule.semver}`
if (updateResult) {
Expand Down