Skip to content
Myr

command.usage.test.js

This file

Path

tests/command.usage.test.js

99 lines · 2.7 KiB · JavaScript

Last changed by

Allow disabling the built-in help option (#1325)John Geebefore adoption6b2e42c

History of this file

Take it

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 1–5why, 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();5

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 6why, one step back
6 program.name('test');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 7–17why, one step back
7 const helpInformation = program.helpInformation();
89 expect(helpInformation).toMatch(new RegExp('^Usage: test \\[options\\]'));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);17

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 18why, one step back
18 program.name('test');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 19–28why, one step back
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');28

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 29why, one step back
29 program.name('test');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 30–41why, one step back
30 const helpInformation = subCommand.helpInformation();
3132 expect(helpInformation).toMatch(new RegExp('^Usage: test info \\[options\\]'));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);41

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

line 42why, one step back
42 program.name('test');

Move to Jest as testing framework (#1035)John Geebefore adoptiond7f9cd4

lines 43–46why, one step back
43 const helpInformation = subCommand.helpInformation();
4445 expect(helpInformation).toMatch(new RegExp(`^Usage: test info ${myUsage}`));46});

Allow disabling the built-in help option (#1325)John Geebefore adoption6b2e42c

lines 47–99why, one step back
47
48test('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});8081test('when arguments then arguments included in usage', () => {82 const program = new commander.Command();8384 program85 .arguments('<file>');8687 expect(program.usage()).toMatch('<file>');88});8990test('when options and command and arguments then all three included in usage', () => {91 const program = new commander.Command();9293 program94 .arguments('<file>')95 .option('--alpha')96 .command('beta');9798 expect(program.usage()).toEqual('[options] [command] <file>');99});