Skip to content
Myr

command.usage.test.js

This file

Path

tests/command.usage.test.js

99 lines · 2.6 KiB · JavaScript

Last changed by

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

History of this file

Take it

The walk stopped after 200 commits: lines older than 9c7cfc0 point at it.

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 1–8why, one step back
1const commander = require('../');
23test('when default usage and check program help then starts with default usage', () => {4 const program = new commander.Command();56 program.name('test');7 const helpInformation = program.helpInformation();8

Update dependencies in 7.x (#1412)John Geebefore adoption469acc9

line 9why, one step back
9 expect(helpInformation).toMatch(/^Usage: test \[options\]/);

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 10–31why, one step back
10});
1112test('when custom usage and check program help then starts with custom usage', () => {13 const myUsage = 'custom';14 const program = new commander.Command();15 program16 .usage(myUsage);1718 program.name('test');19 const helpInformation = program.helpInformation();2021 expect(helpInformation).toMatch(new RegExp(`^Usage: test ${myUsage}`));22});2324test('when default usage and check subcommand help then starts with default usage including program name', () => {25 const program = new commander.Command();26 const subCommand = program27 .command('info');2829 program.name('test');30 const helpInformation = subCommand.helpInformation();31

Update dependencies in 7.x (#1412)John Geebefore adoption469acc9

line 32why, one step back
32 expect(helpInformation).toMatch(/^Usage: test info \[options\]/);

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 33–80why, one step back
33});
3435test('when custom usage and check subcommand help then starts with custom usage including program name', () => {36 const myUsage = 'custom';37 const program = new commander.Command();38 const subCommand = program39 .command('info')40 .usage(myUsage);4142 program.name('test');43 const helpInformation = subCommand.helpInformation();4445 expect(helpInformation).toMatch(new RegExp(`^Usage: test info ${myUsage}`));46});4748test('when has option then [options] included in usage', () => {49 const program = new commander.Command();5051 program52 .option('--foo');5354 expect(program.usage()).toMatch('[options]');55});5657test('when no options then [options] not included in usage', () => {58 const program = new commander.Command();5960 program61 .helpOption(false);6263 expect(program.usage()).not.toMatch('[options]');64});6566test('when has command then [command] included in usage', () => {67 const program = new commander.Command();6869 program70 .command('foo');7172 expect(program.usage()).toMatch('[command]');73});7475test('when no commands then [command] not included in usage', () => {76 const program = new commander.Command();7778 expect(program.usage()).not.toMatch('[command]');79});80

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 81why, one step back
81test('when argument then argument included in usage', () => {

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 82–84why, one step back
82 const program = new commander.Command();
8384 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 85why, one step back
85 .argument('<file>');

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 86–89why, one step back
86
87 expect(program.usage()).toMatch('<file>');88});89

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 90why, one step back
90test('when options and command and argument then all three included in usage', () => {

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 91–93why, one step back
91 const program = new commander.Command();
9293 program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 94why, one step back
94 .argument('<file>')

Prepare for 6.1.0John Geebefore adoption9c7cfc0

lines 95–99why, one step back
95 .option('--alpha')
96 .command('beta');9798 expect(program.usage()).toEqual('[options] [command] <file>');99});