/
checkInvalidCLIOptions.test.js
55 lines (50 loc) · 1.39 KB
/
checkInvalidCLIOptions.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
'use strict';
const chalk = require('chalk');
const checkInvalidCLIOptions = require('../checkInvalidCLIOptions');
const EOL = require('os').EOL;
describe('checkInvalidCLIOptions', () => {
const allowedOptions = {
fix: {},
config: {},
maxWar: { alias: 'mw' },
quiet: { alias: 'q' },
};
it('returns a message when check fails', () => {
const inputOptions = {
fis: true,
fi: true,
fixx: true,
aix: true,
conig: true,
mxWar: true,
ma: true,
q: true,
o: true,
};
const { red: r, cyan: c } = chalk;
expect(checkInvalidCLIOptions(allowedOptions, inputOptions)).toBe(
`Invalid option ${r('"--fis"')}. Did you mean ${c('"--fix"')}?
Invalid option ${r('"--fi"')}. Did you mean ${c('"--fix"')}?
Invalid option ${r('"--fixx"')}. Did you mean ${c('"--fix"')}?
Invalid option ${r('"--aix"')}. Did you mean ${c('"--fix"')}?
Invalid option ${r('"--conig"')}. Did you mean ${c('"--config"')}?
Invalid option ${r('"--mx-war"')}. Did you mean ${c('"--max-war"')}?
Invalid option ${r('"--ma"')}. Did you mean ${c('"--mw"')}?
Invalid option ${r('"-o"')}.
`.replace(/\n/g, EOL),
);
});
it('returns an empty string when check succeeds', () => {
expect(checkInvalidCLIOptions(allowedOptions, {})).toBe('');
expect(
checkInvalidCLIOptions(allowedOptions, {
fix: true,
config: true,
maxWar: true,
mw: true,
quiet: true,
q: true,
}),
).toBe('');
});
});