Skip to content
Myr

command.showHelpAfterError.test.js

This file

Path

tests/command.showHelpAfterError.test.js

139 lines · 4.2 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–3why, one step back
1import * as commander from '../index.js';
2import { test, describe, mock } from 'node:test';3import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 4why, one step back
4

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

line 5why, one step back
5describe('Command.showHelpAfterError(message)', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 6–7why, one step back
6 const customHelpMessage = 'See --help';
7

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

lines 8–9why, one step back
8 function makeProgram(t) {
9 const writeMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 10–18why, one step back
10 const program = new commander.Command();
11 program12 .exitOverride()13 .showHelpAfterError(customHelpMessage)14 .configureOutput({ writeErr: writeMock });1516 return { program, writeMock };17 }18

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

lines 19–20why, one step back
19 test('when missing command-argument then shows help', (t) => {
20 const { program, writeMock } = makeProgram(t);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

lines 22–31why, one step back
22 assert.throws(
23 () => {24 program.parse([], { from: 'user' });25 },26 {27 code: 'commander.missingArgument',28 },29 );30 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];31 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 32–33why, one step back
32 });
33

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

lines 34–35why, one step back
34 test('when missing option-argument then shows help', (t) => {
35 const { program, writeMock } = makeProgram(t);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 36why, one step back
36 program.option('--output <file>');

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

lines 37–46why, one step back
37 assert.throws(
38 () => {39 program.parse(['--output'], { from: 'user' });40 },41 {42 code: 'commander.optionMissingArgument',43 },44 );45 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];46 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 47–48why, one step back
47 });
48

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

lines 49–50why, one step back
49 test('when missing mandatory option then shows help', (t) => {
50 const { program, writeMock } = makeProgram(t);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 51why, one step back
51 program.requiredOption('--password <cipher>');

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

lines 52–61why, one step back
52 assert.throws(
53 () => {54 program.parse([], { from: 'user' });55 },56 {57 code: 'commander.missingMandatoryOptionValue',58 },59 );60 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];61 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 62–63why, one step back
62 });
63

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

lines 64–75why, one step back
64 test('when unknown option then shows help', (t) => {
65 const { program, writeMock } = makeProgram(t);66 assert.throws(67 () => {68 program.parse(['--unknown-option'], { from: 'user' });69 },70 {71 code: 'commander.unknownOption',72 },73 );74 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];75 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

lines 78–79why, one step back
78 test('when too many command-arguments then shows help', (t) => {
79 const { program, writeMock } = makeProgram(t);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 80why, one step back
80 program.allowExcessArguments(false);

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

lines 81–90why, one step back
81 assert.throws(
82 () => {83 program.parse(['surprise'], { from: 'user' });84 },85 {86 code: 'commander.excessArguments',87 },88 );89 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];90 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 91–92why, one step back
91 });
92

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

lines 93–94why, one step back
93 test('when unknown command then shows help', (t) => {
94 const { program, writeMock } = makeProgram(t);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 95why, one step back
95 program.command('sub1');

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

lines 96–105why, one step back
96 assert.throws(
97 () => {98 program.parse(['sub2'], { from: 'user' });99 },100 {101 code: 'commander.unknownCommand',102 },103 );104 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];105 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 106–107why, one step back
106 });
107

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

lines 108–109why, one step back
108 test('when invalid option choice then shows help', (t) => {
109 const { program, writeMock } = makeProgram(t);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 110why, one step back
110 program.addOption(new commander.Option('--color').choices(['red', 'blue']));

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

lines 111–120why, one step back
111 assert.throws(
112 () => {113 program.parse(['--color', 'pink'], { from: 'user' });114 },115 {116 code: 'commander.invalidArgument',117 },118 );119 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];120 assert.equal(lastCall.arguments[0], `${customHelpMessage}\n`);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 121–123why, one step back
121 });
122});123

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

line 124why, one step back
124test('when Command.showHelpAfterError() and error and then shows full help', () => {

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

line 125why, one step back
125 const writeMock = mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 126–133why, one step back
126 const program = new commander.Command();
127 program128 .exitOverride()129 .showHelpAfterError()130 .configureOutput({ writeErr: writeMock });131132 try {133 program.parse(['--unknown-option'], { from: 'user' });

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 134–136why, one step back
134 } catch (err) {
135 /* empty */136 }

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

lines 137–138why, one step back
137 const lastCall = writeMock.mock.calls[writeMock.mock.calls.length - 1];
138 assert.equal(lastCall.arguments[0], program.helpInformation());

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 139why, one step back
139});