Skip to content
Myr

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 file

Take 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 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();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 back
15 program.usage(myUsage);

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 16–24why, one step back
16
17 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 back
25 const subCommand = program.command('info');

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 26–35why, one step back
26
27 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 back
36 const subCommand = program.command('info').usage(myUsage);

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 37–46why, one step back
37
38 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();46

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 47why, one step back
47 program.option('--foo');

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 48–54why, one step back
48
49 expect(program.usage()).toMatch('[options]');50});5152test('when no options then [options] not included in usage', () => {53 const program = new commander.Command();54

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 55why, one step back
55 program.helpOption(false);

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 56–62why, one step back
56
57 expect(program.usage()).not.toMatch('[options]');58});5960test('when has command then [command] included in usage', () => {61 const program = new commander.Command();62

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 63why, one step back
63 program.command('foo');

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 64–76why, one step back
64
65 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();76

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 78–84why, one step back
78
79 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();84

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 85why, one step back
85 program.argument('<file>').option('--alpha').command('beta');

Tidy up some old examples (#1604)John Geebefore adoptionc1472bc

lines 86–88why, one step back
86
87 expect(program.usage()).toEqual('[options] [command] <file>');88});