command.usage.test.js
This file
Path
tests/command.usage.test.js
88 lines · 2.6 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than c1472bc point at it.
Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 1–14why, one step back1const 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();89 expect(helpInformation).toMatch(/^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();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 15why, one step back15 program.usage(myUsage);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 16–24why, one step back1617 program.name('test');18 const helpInformation = program.helpInformation();1920 expect(helpInformation).toMatch(new RegExp(`^Usage: test ${myUsage}`));21});2223test('when default usage and check subcommand help then starts with default usage including program name', () => {24 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 25why, one step back25 const subCommand = program.command('info');Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 26–35why, one step back2627 program.name('test');28 const helpInformation = subCommand.helpInformation();2930 expect(helpInformation).toMatch(/^Usage: test info \[options\]/);31});3233test('when custom usage and check subcommand help then starts with custom usage including program name', () => {34 const myUsage = 'custom';35 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 36why, one step back36 const subCommand = program.command('info').usage(myUsage);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 37–46why, one step back3738 program.name('test');39 const helpInformation = subCommand.helpInformation();4041 expect(helpInformation).toMatch(new RegExp(`^Usage: test info ${myUsage}`));42});4344test('when has option then [options] included in usage', () => {45 const program = new commander.Command();46Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 47why, one step back47 program.option('--foo');Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 48–54why, one step back4849 expect(program.usage()).toMatch('[options]');50});5152test('when no options then [options] not included in usage', () => {53 const program = new commander.Command();54Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 55why, one step back55 program.helpOption(false);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 56–62why, one step back5657 expect(program.usage()).not.toMatch('[options]');58});5960test('when has command then [command] included in usage', () => {61 const program = new commander.Command();62Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 63why, one step back63 program.command('foo');Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 64–76why, one step back6465 expect(program.usage()).toMatch('[command]');66});6768test('when no commands then [command] not included in usage', () => {69 const program = new commander.Command();7071 expect(program.usage()).not.toMatch('[command]');72});7374test('when argument then argument included in usage', () => {75 const program = new commander.Command();76Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 77why, one step back77 program.argument('<file>');Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 78–84why, one step back7879 expect(program.usage()).toMatch('<file>');80});8182test('when options and command and argument then all three included in usage', () => {83 const program = new commander.Command();84Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 85why, one step back85 program.argument('<file>').option('--alpha').command('beta');Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 86–88why, one step back8687 expect(program.usage()).toEqual('[options] [command] <file>');88});