Skip to content

Commit dee58c6

Browse files
committed
Add a test case for calling --version in CLI
For gatsbyjs#249
1 parent 92e2acd commit dee58c6

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

test/integration/cli-returns-help.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import test from 'ava'
2+
import packageJson from '../../package.json'
23
import { gatsby } from '../support'
34

45
test('cli can be called and exits with 0', async t => {
@@ -17,3 +18,15 @@ test('cli returns help when called with unknown args', async t => {
1718
const help = await gatsby(['--help'])
1819
t.is(asdf.stdout, help.stdout)
1920
})
21+
22+
test('cli does not return help when called with --version', async t => {
23+
const version = await gatsby(['--version'])
24+
const help = await gatsby(['--help'])
25+
t.not(version.stdout, help.stdout)
26+
})
27+
28+
test('cli returns the gatsby version when called with --version', async t => {
29+
const versionCli = await gatsby(['--version'])
30+
const versionPackage = packageJson.version
31+
t.true(versionCli.stdout.indexOf(versionPackage) > -1)
32+
})

test/support.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export function spawn (command, args = [], options = {}) {
2727
}
2828

2929
export function gatsby (args = [], options = {}) {
30-
const spawnArguments = concat([gatsbyCli], args)
30+
const spawnArguments = concat(['--', gatsbyCli], args)
3131
return spawn(babel, spawnArguments, options)
3232
}
3333

3434
export function build (fixturePath) {
3535
const buildPath = path.resolve(fixturePath, 'public')
3636
return remove(buildPath)
37-
.then(() => spawn(babel, [gatsbyCli, 'build'], { cwd: fixturePath }))
37+
.then(() => gatsby(['build'], { cwd: fixturePath }))
3838
}
3939

4040
export function dom (filePath) {

0 commit comments

Comments
 (0)