Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test coverage #1433

Merged
merged 6 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/args.variadic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ describe('variadic argument', () => {
program.command('sub <variadicArg...> [optionalArg]');
}).toThrow("only the last argument can be variadic 'variadicArg'");
});

test('when variadic argument then usage shows variadic', () => {
const program = new commander.Command();
program
.name('foo')
.arguments('[args...]');

expect(program.usage()).toBe('[options] [args...]');
});
});
16 changes: 16 additions & 0 deletions tests/command.helpOption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ describe('helpOption', () => {
expect(helpInformation).toMatch(/-C,--custom-help +custom help output/);
});

test('when helpOption has just flags then helpInformation includes default description', () => {
const program = new commander.Command();
program
.helpOption('-C,--custom-help');
const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(/-C,--custom-help +display help for command/);
});

test('when helpOption has just description then helpInformation includes default flags', () => {
const program = new commander.Command();
program
.helpOption(undefined, 'custom help output');
const helpInformation = program.helpInformation();
expect(helpInformation).toMatch(/-h, --help +custom help output/);
});

test('when helpOption(false) then helpInformation does not include --help', () => {
const program = new commander.Command();
program
Expand Down
9 changes: 8 additions & 1 deletion tests/help.wrap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ const commander = require('../');
// There is some overlap with the higher level Command tests (which predate Help).

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

test('when string shorter than indent then returns input', () => {
const text = 'a';
const helper = new commander.Help();
const wrapped = helper.wrap(text, 50, 3);
expect(wrapped).toEqual(text);
});

test('when string exceeds width then wrap', () => {
const text = 'a '.repeat(30) + 'a';
const helper = new commander.Help();
Expand Down
10 changes: 10 additions & 0 deletions tests/options.bool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ describe('boolean flag with non-boolean default', () => {
program.parse(['node', 'test', '--olives']);
expect(program.opts().olives).toBe(flagValue);
});

test('when flag implied and negated then value is false', () => {
const flagValue = 'black';
const program = new commander.Command();
program
.option('-v, --olives', 'Add olives? Sorry we only have black.', flagValue)
.option('--no-olives');
program.parse(['node', 'test', '--olives', '--no-olives']);
expect(program.opts().olives).toBe(false);
});
});

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