/
cli.test.js
140 lines (114 loc) · 4.27 KB
/
cli.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
const { buildCLI } = require('../cli');
describe('buildCLI', () => {
it('flags - default', () => {
expect(buildCLI([]).flags).toEqual({
allowEmptyInput: false,
cache: false,
color: false,
disableDefaultIgnores: false,
fix: false,
formatter: 'string',
help: false,
ignoreDisables: false,
printConfig: false,
quiet: false,
reportInvalidScopeDisables: false,
reportNeedlessDisables: false,
version: false,
});
});
it('flags.allowEmptyInput', () => {
expect(buildCLI(['--allow-empty-input']).flags.allowEmptyInput).toBe(true);
expect(buildCLI(['--aei']).flags.allowEmptyInput).toBe(true);
});
it('flags.cache', () => {
expect(buildCLI(['--cache']).flags.cache).toBe(true);
});
it('flags.cacheLocation', () => {
expect(buildCLI(['--cache-location=foo']).flags.cacheLocation).toBe('foo');
});
it('flags.color', () => {
expect(buildCLI(['--color']).flags.color).toBe(true);
expect(buildCLI(['--no-color']).flags.color).toBe(false);
});
it('flags.config', () => {
expect(buildCLI(['--config=/path/to/file']).flags.config).toBe('/path/to/file');
});
it('flags.configBasedir', () => {
expect(buildCLI(['--config-basedir=/path/to/dir']).flags.configBasedir).toBe('/path/to/dir');
});
it('flags.customFormatter', () => {
expect(buildCLI(['--custom-formatter=foo']).flags.customFormatter).toBe('foo');
});
it('flags.customSyntax', () => {
expect(buildCLI(['--custom-syntax=foo']).flags.customSyntax).toBe('foo');
});
it('flags.disableDefaultIgnores', () => {
expect(buildCLI(['--disable-default-ignores']).flags.disableDefaultIgnores).toBe(true);
expect(buildCLI(['--di']).flags.disableDefaultIgnores).toBe(true);
});
it('flags.fix', () => {
expect(buildCLI(['--fix']).flags.fix).toBe(true);
});
it('flags.formatter', () => {
expect(buildCLI(['--formatter=json']).flags.formatter).toBe('json');
expect(buildCLI(['-f', 'json']).flags.formatter).toBe('json');
});
it('flags.help', () => {
expect(buildCLI(['--help']).flags.help).toBe(true);
expect(buildCLI(['-h']).flags.help).toBe(true);
});
it('flags.ignoreDisables', () => {
expect(buildCLI(['--ignore-disables']).flags.ignoreDisables).toBe(true);
expect(buildCLI(['--id']).flags.ignoreDisables).toBe(true);
});
it('flags.ignorePath', () => {
expect(buildCLI(['--ignore-path=/path/to/file']).flags.ignorePath).toBe('/path/to/file');
expect(buildCLI(['-i', '/path/to/file']).flags.ignorePath).toBe('/path/to/file');
});
it('flags.ignorePattern', () => {
expect(buildCLI(['--ignore-pattern=vendor/**']).flags.ignorePattern).toBe('vendor/**');
expect(buildCLI(['--ip', 'vendor/**']).flags.ignorePattern).toBe('vendor/**');
expect(buildCLI(['--ip', 'vendor/**', '--ip', 'test/*.css']).flags.ignorePattern).toEqual([
'vendor/**',
'test/*.css',
]);
});
it('flags.maxWarnings', () => {
expect(buildCLI(['--max-warnings=7']).flags.maxWarnings).toBe(7);
expect(buildCLI(['--mw', '-1']).flags.maxWarnings).toBe(-1);
});
it('flags.outputFile', () => {
expect(buildCLI(['--output-file=/path/to/file']).flags.outputFile).toBe('/path/to/file');
expect(buildCLI(['-o', '/path/to/file']).flags.outputFile).toBe('/path/to/file');
});
it('flags.printConfig', () => {
expect(buildCLI(['--print-config']).flags.printConfig).toBe(true);
});
it('flags.quiet', () => {
expect(buildCLI(['--quiet']).flags.quiet).toBe(true);
expect(buildCLI(['-q']).flags.quiet).toBe(true);
});
it('flags.reportInvalidScopeDisables', () => {
expect(buildCLI(['--report-invalid-scope-disables']).flags.reportInvalidScopeDisables).toBe(
true,
);
expect(buildCLI(['--risd']).flags.reportInvalidScopeDisables).toBe(true);
});
it('flags.reportNeedlessDisables', () => {
expect(buildCLI(['--report-needless-disables']).flags.reportNeedlessDisables).toBe(true);
expect(buildCLI(['--rd']).flags.reportNeedlessDisables).toBe(true);
});
it('flags.stdinFilename', () => {
expect(buildCLI(['--stdin-filename=foo.css']).flags.stdinFilename).toBe('foo.css');
});
it('flags.syntax', () => {
expect(buildCLI(['--syntax=less']).flags.syntax).toBe('less');
expect(buildCLI(['-s', 'less']).flags.syntax).toBe('less');
});
it('flags.version', () => {
expect(buildCLI(['--version']).flags.version).toBe(true);
expect(buildCLI(['-v']).flags.version).toBe(true);
});
});