/
command.usage.test.js
99 lines (70 loc) · 2.65 KB
/
command.usage.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
const commander = require('../');
test('when default usage and check program help then starts with default usage', () => {
const program = new commander.Command();
program.name('test');
const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(new RegExp('^Usage: test \\[options\\]'));
});
test('when custom usage and check program help then starts with custom usage', () => {
const myUsage = 'custom';
const program = new commander.Command();
program
.usage(myUsage);
program.name('test');
const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(new RegExp(`^Usage: test ${myUsage}`));
});
test('when default usage and check subcommand help then starts with default usage including program name', () => {
const program = new commander.Command();
const subCommand = program
.command('info');
program.name('test');
const helpInformation = subCommand.helpInformation();
expect(helpInformation).toMatch(new RegExp('^Usage: test info \\[options\\]'));
});
test('when custom usage and check subcommand help then starts with custom usage including program name', () => {
const myUsage = 'custom';
const program = new commander.Command();
const subCommand = program
.command('info')
.usage(myUsage);
program.name('test');
const helpInformation = subCommand.helpInformation();
expect(helpInformation).toMatch(new RegExp(`^Usage: test info ${myUsage}`));
});
test('when has option then [options] included in usage', () => {
const program = new commander.Command();
program
.option('--foo');
expect(program.usage()).toMatch('[options]');
});
test('when no options then [options] not included in usage', () => {
const program = new commander.Command();
program
.helpOption(false);
expect(program.usage()).not.toMatch('[options]');
});
test('when has command then [command] included in usage', () => {
const program = new commander.Command();
program
.command('foo');
expect(program.usage()).toMatch('[command]');
});
test('when no commands then [command] not included in usage', () => {
const program = new commander.Command();
expect(program.usage()).not.toMatch('[command]');
});
test('when arguments then arguments included in usage', () => {
const program = new commander.Command();
program
.arguments('<file>');
expect(program.usage()).toMatch('<file>');
});
test('when options and command and arguments then all three included in usage', () => {
const program = new commander.Command();
program
.arguments('<file>')
.option('--alpha')
.command('beta');
expect(program.usage()).toEqual('[options] [command] <file>');
});