-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathargs.test.ts
64 lines (63 loc) · 1.89 KB
/
args.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { getArg } from '../src/utils/args'
describe('args', () => {
it('should capture an arg name from text', () => {
const args = ['--name', 'value']
const result = getArg(args, { name: 'name' })
expect(result).toBe('value')
})
it('should capture an arg alias from text', () => {
const args = ['-n', 'value']
const result = getArg(args, { name: 'name', alias: 'n' })
expect(result).toBe('value')
})
it('should capture an arg name from text when starting values', () => {
const args = ['dir', '--name', 'value']
const result = getArg(args, { name: 'name' })
expect(result).toBe('value')
})
it('should capture an arg alias from text', () => {
const args = ['dir', '-n', 'value']
const result = getArg(args, { name: 'name', alias: 'n' })
expect(result).toBe('value')
})
it('should convert bool string to true', () => {
const args = ['--someBool', 'true']
const result = getArg(args, {
name: 'someBool',
alias: 'sb'
})
expect(result).toBe('true')
})
it('should convert bool string to false', () => {
const args = ['--someBool', 'false']
const result = getArg(args, {
name: 'someBool',
alias: 'sb'
})
expect(result).toBe('false')
})
it('should default value to true if no next value', () => {
const args = ['--someBool']
const result = getArg(args, {
name: 'someBool',
alias: 'sb'
})
expect(result).toBe(null)
})
it('should default value to true if next value is --name', () => {
const args = ['--someBool', '--someOtherBool']
const result = getArg(args, {
name: 'someBool',
alias: 'sb'
})
expect(result).toBe(null)
})
it('should default value to true if next value is -alias', () => {
const args = ['--someBool', '-a']
const result = getArg(args, {
name: 'someBool',
alias: 'sb'
})
expect(result).toBe(null)
})
})