Skip to content

Commit d948b0f

Browse files
committed
Add tests
1 parent fc7a0ba commit d948b0f

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

test/helpers/parse.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { parseArgv } from '../../src/helpers/parse'
2+
3+
4+
test( 'deploymentEnv arg is parsed into same deploymentEnv string', () => {
5+
const argv = [,,'production']
6+
7+
expect(parseArgv(argv)).toMatchObject({
8+
deploymentEnv: 'production'
9+
})
10+
})
11+
12+
13+
test( 'No ENV_VAR arg is parsed as null', () => {
14+
const argv = [,,'production']
15+
16+
expect(parseArgv(argv)).toMatchObject({
17+
varNameList: null
18+
})
19+
})
20+
21+
22+
test( 'Single ENV_VAR arg is parsed into [string]', () => {
23+
const argv = [,,'production','API_KEY']
24+
25+
expect(parseArgv(argv)).toMatchObject({
26+
varNameList: ['API_KEY']
27+
})
28+
})
29+
30+
31+
test( 'Multiple ENV_VAR args are parsed into string[]', () => {
32+
const argv = [,,'production','API_KEY','SECRET','GRAPHQL_ENDPOINT']
33+
34+
expect(parseArgv(argv)).toMatchObject({
35+
varNameList: ['API_KEY','SECRET','GRAPHQL_ENDPOINT']
36+
})
37+
})
38+
39+
40+
test( 'Invalid arg shoud print help message to stdout', () => {
41+
const argv = [,,'basilisk']
42+
43+
jest.spyOn(console, 'log')
44+
// handle process.exit so test doesn't error
45+
jest.spyOn(process, 'exit').mockImplementation()
46+
47+
parseArgv(argv)
48+
49+
const stdout = 'Usage: deploy-env [production | preview | development] [ENV_VAR]...'
50+
expect(console.log).toHaveBeenCalledWith(stdout)
51+
})
52+
53+
54+
test( 'Invalid arg should exit process with code 9', () => {
55+
const argv = [,,'basilisk']
56+
57+
parseArgv(argv)
58+
59+
const exitCode = 9
60+
expect(process.exit).toHaveBeenCalledWith(exitCode)
61+
})

0 commit comments

Comments
 (0)