Skip to content

Commit 891e23d

Browse files
authored
Test coverage (#1433)
* Test for just flags and just description * Edge case test for wrap with trivial input * Add obscure edge case for coverage * Add test for variadic argument usage/help * Suppress tests that uncredited coverage and not currently chasing * Revert "Suppress tests that uncredited coverage and not currently chasing" This reverts commit d3c9146.
1 parent ff301fa commit 891e23d

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

tests/args.variadic.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ describe('variadic argument', () => {
6868
program.command('sub <variadicArg...> [optionalArg]');
6969
}).toThrow("only the last argument can be variadic 'variadicArg'");
7070
});
71+
72+
test('when variadic argument then usage shows variadic', () => {
73+
const program = new commander.Command();
74+
program
75+
.name('foo')
76+
.arguments('[args...]');
77+
78+
expect(program.usage()).toBe('[options] [args...]');
79+
});
7180
});

tests/command.helpOption.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ describe('helpOption', () => {
6868
expect(helpInformation).toMatch(/-C,--custom-help +custom help output/);
6969
});
7070

71+
test('when helpOption has just flags then helpInformation includes default description', () => {
72+
const program = new commander.Command();
73+
program
74+
.helpOption('-C,--custom-help');
75+
const helpInformation = program.helpInformation();
76+
expect(helpInformation).toMatch(/-C,--custom-help +display help for command/);
77+
});
78+
79+
test('when helpOption has just description then helpInformation includes default flags', () => {
80+
const program = new commander.Command();
81+
program
82+
.helpOption(undefined, 'custom help output');
83+
const helpInformation = program.helpInformation();
84+
expect(helpInformation).toMatch(/-h, --help +custom help output/);
85+
});
86+
7187
test('when helpOption(false) then helpInformation does not include --help', () => {
7288
const program = new commander.Command();
7389
program

tests/help.wrap.test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ const commander = require('../');
44
// There is some overlap with the higher level Command tests (which predate Help).
55

66
describe('wrap', () => {
7-
test('when string fits into width then no wrap', () => {
7+
test('when string fits into width then returns input', () => {
88
const text = 'a '.repeat(24) + 'a';
99
const helper = new commander.Help();
1010
const wrapped = helper.wrap(text, 50, 3);
1111
expect(wrapped).toEqual(text);
1212
});
1313

14+
test('when string shorter than indent then returns input', () => {
15+
const text = 'a';
16+
const helper = new commander.Help();
17+
const wrapped = helper.wrap(text, 50, 3);
18+
expect(wrapped).toEqual(text);
19+
});
20+
1421
test('when string exceeds width then wrap', () => {
1522
const text = 'a '.repeat(30) + 'a';
1623
const helper = new commander.Help();

tests/options.bool.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,16 @@ describe('boolean flag with non-boolean default', () => {
106106
program.parse(['node', 'test', '--olives']);
107107
expect(program.opts().olives).toBe(flagValue);
108108
});
109+
110+
test('when flag implied and negated then value is false', () => {
111+
const flagValue = 'black';
112+
const program = new commander.Command();
113+
program
114+
.option('-v, --olives', 'Add olives? Sorry we only have black.', flagValue)
115+
.option('--no-olives');
116+
program.parse(['node', 'test', '--olives', '--no-olives']);
117+
expect(program.opts().olives).toBe(false);
118+
});
109119
});
110120

111121
// Regression test for #1301 with `-no-` in middle of option

0 commit comments

Comments
 (0)