forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.utils.test.js
73 lines (53 loc) · 1.93 KB
/
cli.utils.test.js
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
65
66
67
68
69
70
71
72
73
import * as utils from '../src/cli/utils'
describe('cli utils', () => {
describe('parseCliParams', () => {
it('parses CLI parameters', () => {
const result = utils.parseCliParams(['a', 'b', '-c', 'd'])
expect(result).toEqual(['a', 'b'])
})
})
describe('parseCliOptions', () => {
it('parses CLI options', () => {
const result = utils.parseCliOptions(['a', '-b', 'c'], { test: ['b'] })
expect(result).toEqual({ test: ['c'] })
})
it('parses multiple types of options', () => {
const result = utils.parseCliOptions(['a', '-b', 'c', '--test', 'd', '-test', 'e'], {
test: ['test', 'b'],
})
expect(result).toEqual({ test: ['c', 'd', 'e'] })
})
it('ignores unknown options', () => {
const result = utils.parseCliOptions(['a', '-b', 'c'], {})
expect(result).toEqual({})
})
it('maps options', () => {
const result = utils.parseCliOptions(['a', '-b', 'c', '-d', 'e'], { test: ['b', 'd'] })
expect(result).toEqual({ test: ['c', 'e'] })
})
it('parses undefined options', () => {
const result = utils.parseCliOptions(['a'], { test: ['b'] })
expect(result).toEqual({ test: undefined })
})
it('parses flags', () => {
const result = utils.parseCliOptions(['a', '-b'], { test: ['b'] })
expect(result).toEqual({ test: [] })
})
it('accepts multiple values per option', () => {
const result = utils.parseCliOptions(['a', '-b', 'c', 'd', '-e', 'f', '-g', 'h'], {
test: ['b', 'g'],
})
expect(result).toEqual({ test: ['c', 'd', 'h'] })
})
})
describe('getSimplePath', () => {
it('strips leading ./', () => {
const result = utils.getSimplePath('./test')
expect(result).toEqual('test')
})
it('returns unchanged path if it does not begin with ./', () => {
const result = utils.getSimplePath('../test')
expect(result).toEqual('../test')
})
})
})