Skip to content
Myr

command.helpOption.test.js

This file

Path

tests/command.helpOption.test.js

127 lines · 4.3 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

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

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 1–4why, one step back
1import * as commander from '../index.js';
2import { createTestCommand } from './testHelpers.js';3import { test, describe } from 'node:test';4import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 5why, one step back
5

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

line 6why, one step back
6describe('Command.helpOption()', () => {

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

lines 7–15why, one step back
7 test('when helpOption has custom flags then custom short flag invokes help', (t) => {
8 const program = createTestCommand();9 program.helpOption('-c,--custom-help', 'custom help output');10 assert.throws(11 () => {12 program.parse(['-c'], { from: 'user' });13 },14 { message: '(outputHelp)' },15 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 16–17why, one step back
16 });
17

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

lines 18–26why, one step back
18 test('when helpOption has custom flags then custom long flag invokes help', (t) => {
19 const program = createTestCommand();20 program.helpOption('-c,--custom-help', 'custom help output');21 assert.throws(22 () => {23 program.parse(['--custom-help'], { from: 'user' });24 },25 { message: '(outputHelp)' },26 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 27–28why, one step back
27 });
28

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

lines 29–37why, one step back
29 test('when helpOption has just custom short flag then custom short flag invokes help', (t) => {
30 const program = createTestCommand();31 program.helpOption('-c', 'custom help output');32 assert.throws(33 () => {34 program.parse(['-c'], { from: 'user' });35 },36 { message: '(outputHelp)' },37 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 38–39why, one step back
38 });
39

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

lines 40–48why, one step back
40 test('when helpOption has just custom long flag then custom long flag invokes help', (t) => {
41 const program = createTestCommand();42 program.helpOption('--custom-help', 'custom help output');43 assert.throws(44 () => {45 program.parse(['--custom-help'], { from: 'user' });46 },47 { message: '(outputHelp)' },48 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 49–52why, one step back
49 });
5051 test('when helpOption has custom description then helpInformation include custom description', () => {52 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 53why, one step back
53 program.helpOption('-C,--custom-help', 'custom help output');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 54why, one step back
54 const helpInformation = program.helpInformation();

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

line 55why, one step back
55 assert.match(helpInformation, /-C,--custom-help +custom help output/);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 56–59why, one step back
56 });
5758 test('when helpOption has just flags then helpInformation includes default description', () => {59 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 60why, one step back
60 program.helpOption('-C,--custom-help');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 61why, one step back
61 const helpInformation = program.helpInformation();

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

line 62why, one step back
62 assert.match(helpInformation, /-C,--custom-help +display help for command/);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 63–66why, one step back
63 });
6465 test('when helpOption has just description then helpInformation includes default flags', () => {66 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 67why, one step back
67 program.helpOption(undefined, 'custom help output');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 68why, one step back
68 const helpInformation = program.helpInformation();

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

line 69why, one step back
69 assert.match(helpInformation, /-h, --help +custom help output/);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 70–73why, one step back
70 });
7172 test('when helpOption(false) then helpInformation does not include --help', () => {73 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 75why, one step back
75 const helpInformation = program.helpInformation();

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

line 76why, one step back
76 assert(!helpInformation.includes('--help'));

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 77–78why, one step back
77 });
78

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

lines 79–87why, one step back
79 test('when helpOption(false) then --help is an unknown option', (t) => {
80 const program = createTestCommand();81 program.helpOption(false);82 assert.throws(83 () => {84 program.parse(['--help'], { from: 'user' });85 },86 { code: 'commander.unknownOption' },87 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 88–89why, one step back
88 });
89

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

lines 90–98why, one step back
90 test('when helpOption(false) then -h is an unknown option', (t) => {
91 const program = createTestCommand();92 program.helpOption(false);93 assert.throws(94 () => {95 program.parse(['-h'], { from: 'user' });96 },97 { code: 'commander.unknownOption' },98 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 99–100why, one step back
99 });
100

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

lines 101–109why, one step back
101 test('when helpOption(false) then unknown command error does not suggest --help', (t) => {
102 const program = createTestCommand();103 program.helpOption(false).command('foo');104 assert.throws(105 () => {106 program.parse(['UNKNOWN'], { from: 'user' });107 },108 { message: "error: unknown command 'UNKNOWN'" },109 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 110why, one step back
110 });

Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3

lines 111–116why, one step back
111
112 test('when helpOption(true) after false then helpInformation does include --help', () => {113 const program = new commander.Command();114 program.helpOption(false);115 program.helpOption(true);116 const helpInformation = program.helpInformation();

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

line 117why, one step back
117 assert(helpInformation.includes('--help'));

Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3

lines 118–124why, one step back
118 });
119120 test('when helpOption(true) after customise then helpInformation still customised', () => {121 const program = new commander.Command();122 program.helpOption('--ASSIST');123 program.helpOption(true);124 const helpInformation = program.helpInformation();

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

line 125why, one step back
125 assert(helpInformation.includes('--ASSIST'));

Add support for groups of options and commands in the help (#2328)John Geebefore adoptionc324ea3

line 126why, one step back
126 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 127why, one step back
127});