Skip to content
Myr

command.helpCommand.test.js

This file

Path

tests/command.helpCommand.test.js

171 lines · 5.5 KiB · JavaScript

Last changed by

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

History of this file

Take it

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

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 1why, one step back
1const commander = require('../');

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

lines 2–4why, one step back
2const { createTestCommand } = require('./testHelpers');
3const { test, describe } = require('node:test');4const assert = require('node:assert/strict');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 5why, one step back
5

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 6–12why, one step back
6describe('help handling of subcommands', () => {
7 describe('help command listed in helpInformation', () => {8 test('when program has no subcommands then no automatic help command', () => {9 const program = new commander.Command();10 const helpInformation = program.helpInformation();11 assert.doesNotMatch(helpInformation, /help \[command\]/);12 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 13why, one step back
13

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 14–19why, one step back
14 test('when program has no subcommands and add help command then has help command', () => {
15 const program = new commander.Command();16 program.addHelpCommand(true);17 const helpInformation = program.helpInformation();18 assert.match(helpInformation, /help \[command\]/);19 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 20why, one step back
20

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 21–26why, one step back
21 test('when program has subcommands then has automatic help command', () => {
22 const program = new commander.Command();23 program.command('foo');24 const helpInformation = program.helpInformation();25 assert.match(helpInformation, /help \[command\]/);26 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 27why, one step back
27

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 28–39why, one step back
28 test('when program has subcommands and specify only unknown option then display help', () => {
29 const program = createTestCommand();30 program.allowUnknownOption().command('foo');31 assert.throws(32 () => {33 program.parse(['--unknown'], { from: 'user' });34 },35 {36 code: 'commander.help',37 },38 );39 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 40why, one step back
40

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 41–47why, one step back
41 test('when program has subcommands and suppress help command then no help command', () => {
42 const program = new commander.Command();43 program.addHelpCommand(false);44 program.command('foo');45 const helpInformation = program.helpInformation();46 assert.doesNotMatch(helpInformation, /help \[command\]/);47 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 48why, one step back
48

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 49–54why, one step back
49 test('when add custom help command then custom help command', () => {
50 const program = new commander.Command();51 program.addHelpCommand('myHelp', 'help description');52 const helpInformation = program.helpInformation();53 assert.match(helpInformation, /myHelp +help description/);54 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 55–56why, one step back
55 });
56

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 57–63why, one step back
57 describe('help command processed on correct command', () => {
58 function makeCommand() {59 const program = new commander.Command();60 program.configureOutput({61 writeOut: () => {},62 writeErr: () => {},63 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 64why, one step back
64

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 65–66why, one step back
65 return program;
66 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 67why, one step back
67

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 68–77why, one step back
68 test('when "program help" then program', () => {
69 const program = makeCommand();70 program.exitOverride();71 program.command('sub1');72 program.exitOverride(() => {73 throw new Error('program');74 });75 assert.throws(() => {76 program.parse('node test.js help'.split(' '));77 }, /program/);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 78why, one step back
78 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 79why, one step back
79

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 80–89why, one step back
80 test('when "program help unknown" then program', () => {
81 const program = makeCommand();82 program.exitOverride();83 program.command('sub1');84 program.exitOverride(() => {85 throw new Error('program');86 });87 assert.throws(() => {88 program.parse('node test.js help unknown'.split(' '));89 }, /program/);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 90why, one step back
90 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 91why, one step back
91

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 92–101why, one step back
92 test('when "program help sub1" then sub1', () => {
93 const program = makeCommand();94 program.exitOverride();95 const sub1 = program.command('sub1');96 sub1.exitOverride(() => {97 throw new Error('sub1');98 });99 assert.throws(() => {100 program.parse('node test.js help sub1'.split(' '));101 }, /sub1/);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 102why, one step back
102 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 103why, one step back
103

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 104–114why, one step back
104 test('when "program sub1 help sub2" then sub2', () => {
105 const program = makeCommand();106 program.exitOverride();107 const sub1 = program.command('sub1');108 const sub2 = sub1.command('sub2');109 sub2.exitOverride(() => {110 throw new Error('sub2');111 });112 assert.throws(() => {113 program.parse('node test.js sub1 help sub2'.split(' '));114 }, /sub2/);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 115why, one step back
115 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 116why, one step back
116

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 117–126why, one step back
117 test('when default command and "program help" then program', () => {
118 const program = makeCommand();119 program.exitOverride();120 program.command('sub1', { isDefault: true });121 program.exitOverride(() => {122 throw new Error('program');123 });124 assert.throws(() => {125 program.parse('node test.js help'.split(' '));126 }, /program/);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 127why, one step back
127 });

Have help command call help directly for subcommands, when possible (#1864)John Geebefore adoption63abdac

line 128why, one step back
128

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 129–141why, one step back
129 test('when no long help flag then "help sub" works', () => {
130 const program = makeCommand();131 program.exitOverride();132 program.helpOption('-H');133 const sub = program.command('sub');134 // Patch help for easy way to check called.135 sub.help = () => {136 throw new Error('sub help');137 };138 assert.throws(() => {139 program.parse(['help', 'sub'], { from: 'user' });140 }, /sub help/);141 });

Have help command call help directly for subcommands, when possible (#1864)John Geebefore adoption63abdac

line 142why, one step back
142

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 143–154why, one step back
143 test('when no help options in sub then "help sub" works', () => {
144 const program = makeCommand();145 program.exitOverride();146 const sub = program.command('sub').helpOption(false);147 // Patch help for easy way to check called.148 sub.help = () => {149 throw new Error('sub help');150 };151 assert.throws(() => {152 program.parse(['help', 'sub'], { from: 'user' });153 }, /sub help/);154 });

Have help command call help directly for subcommands, when possible (#1864)John Geebefore adoption63abdac

line 155why, one step back
155

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 156–169why, one step back
156 test('when different help options in sub then "help sub" works', () => {
157 const program = makeCommand();158 program.exitOverride();159 const sub = program.command('sub');160 program.helpOption('-h, --help');161 sub.helpOption('-a, --assist');162 // Patch help for easy way to check called.163 sub.help = () => {164 throw new Error('sub help');165 };166 assert.throws(() => {167 program.parse(['help', 'sub'], { from: 'user' });168 }, /sub help/);169 });

Have help command call help directly for subcommands, when possible (#1864)John Geebefore adoption63abdac

line 170why, one step back
170 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 171why, one step back
171});