Skip to content
Myr

command.addHelpText.test.js

This file

Path

tests/command.addHelpText.test.js

239 lines · 7.6 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, beforeEach } from 'node:test';3import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 4–6why, one step back
4
5// Using outputHelp to simplify testing.6

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

line 7why, one step back
7describe('Command.addHelpText(): program calls to addHelpText', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 8–9why, one step back
8 let writeSpy;
9

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

lines 10–11why, one step back
10 beforeEach((t) => {
11 writeSpy = t.mock.method(process.stdout, 'write', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 12–17why, one step back
12 });
1314 test('when "before" string then string before built-in help', () => {15 const program = new commander.Command();16 program.addHelpText('before', 'text');17 program.outputHelp();

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

lines 18–22why, one step back
18 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');
19 assert.equal(20 writeSpy.mock.calls[1].arguments[0],21 program.helpInformation(),22 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 23–28why, one step back
23 });
2425 test('when "before" function then function result before built-in help', () => {26 const program = new commander.Command();27 program.addHelpText('before', () => 'text');28 program.outputHelp();

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

lines 29–33why, one step back
29 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');
30 assert.equal(31 writeSpy.mock.calls[1].arguments[0],32 program.helpInformation(),33 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 34–37why, one step back
34 });
3536 test('when "before" function returns nothing then no effect', () => {37 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 38why, one step back
38 program.addHelpText('before', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 39why, one step back
39 program.outputHelp();

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

lines 40–43why, one step back
40 assert.equal(
41 writeSpy.mock.calls[0].arguments[0],42 program.helpInformation(),43 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 44–49why, one step back
44 });
4546 test('when "beforeAll" string then string before built-in help', () => {47 const program = new commander.Command();48 program.addHelpText('beforeAll', 'text');49 program.outputHelp();

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

lines 50–54why, one step back
50 assert.equal(writeSpy.mock.calls[0].arguments[0], 'text\n');
51 assert.equal(52 writeSpy.mock.calls[1].arguments[0],53 program.helpInformation(),54 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 55–60why, one step back
55 });
5657 test('when "after" string then string after built-in help', () => {58 const program = new commander.Command();59 program.addHelpText('after', 'text');60 program.outputHelp();

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

lines 61–65why, one step back
61 assert.equal(
62 writeSpy.mock.calls[0].arguments[0],63 program.helpInformation(),64 );65 assert.equal(writeSpy.mock.calls[1].arguments[0], 'text\n');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 66–71why, one step back
66 });
6768 test('when "afterAll" string then string after built-in help', () => {69 const program = new commander.Command();70 program.addHelpText('afterAll', 'text');71 program.outputHelp();

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

lines 72–76why, one step back
72 assert.equal(
73 writeSpy.mock.calls[0].arguments[0],74 program.helpInformation(),75 );76 assert.equal(writeSpy.mock.calls[1].arguments[0], 'text\n');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 77–85why, one step back
77 });
7879 test('when all the simple positions then strings in order', () => {80 const program = new commander.Command();81 program.addHelpText('before', 'before');82 program.addHelpText('after', 'after');83 program.addHelpText('beforeAll', 'beforeAll');84 program.addHelpText('afterAll', 'afterAll');85 program.outputHelp();

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

lines 86–93why, one step back
86 assert.equal(writeSpy.mock.calls[0].arguments[0], 'beforeAll\n');
87 assert.equal(writeSpy.mock.calls[1].arguments[0], 'before\n');88 assert.equal(89 writeSpy.mock.calls[2].arguments[0],90 program.helpInformation(),91 );92 assert.equal(writeSpy.mock.calls[3].arguments[0], 'after\n');93 assert.equal(writeSpy.mock.calls[4].arguments[0], 'afterAll\n');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 94–97why, one step back
94 });
9596 test('when "silly" position then throw', () => {97 const program = new commander.Command();

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

line 98why, one step back
98 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 99why, one step back
99 program.addHelpText('silly', 'text');

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

line 100why, one step back
100 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 101–103why, one step back
101 });
102});103

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

line 104why, one step back
104describe('Command.addHelpText(): program and subcommand calls to addHelpText', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 105–106why, one step back
105 let writeSpy;
106

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

lines 107–108why, one step back
107 beforeEach((t) => {
108 writeSpy = t.mock.method(process.stdout, 'write', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 109–110why, one step back
109 });
110

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

line 111why, one step back
111 test('when "before" on program then not called on subcommand', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 112–113why, one step back
112 const program = new commander.Command();
113 const sub = program.command('sub');

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

line 114why, one step back
114 const testMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 115–116why, one step back
115 program.addHelpText('before', testMock);
116 sub.outputHelp();

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

line 117why, one step back
117 assert.equal(testMock.mock.callCount(), 0);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 118–119why, one step back
118 });
119

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

line 120why, one step back
120 test('when "beforeAll" on program then is called on subcommand', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 121–122why, one step back
121 const program = new commander.Command();
122 const sub = program.command('sub');

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

line 123why, one step back
123 const testMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 124–125why, one step back
124 program.addHelpText('beforeAll', testMock);
125 sub.outputHelp();

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

line 126why, one step back
126 assert.equal(testMock.mock.callCount(), 1);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 127–128why, one step back
127 });
128

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

line 129why, one step back
129 test('when "after" on program then not called on subcommand', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 130–131why, one step back
130 const program = new commander.Command();
131 const sub = program.command('sub');

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

line 132why, one step back
132 const testMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 133–134why, one step back
133 program.addHelpText('after', testMock);
134 sub.outputHelp();

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

line 135why, one step back
135 assert.equal(testMock.mock.callCount(), 0);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 136–137why, one step back
136 });
137

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

line 138why, one step back
138 test('when "afterAll" on program then is called on subcommand', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 139–140why, one step back
139 const program = new commander.Command();
140 const sub = program.command('sub');

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

line 141why, one step back
141 const testMock = t.mock.fn();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 142–143why, one step back
142 program.addHelpText('afterAll', testMock);
143 sub.outputHelp();

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

line 144why, one step back
144 assert.equal(testMock.mock.callCount(), 1);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 145–147why, one step back
145 });
146});147

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

line 148why, one step back
148describe('Command.addHelpText(): context checks with full parse', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 149–151why, one step back
149 let stdoutSpy;
150 let stderrSpy;151

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

lines 152–154why, one step back
152 beforeEach((t) => {
153 stdoutSpy = t.mock.method(process.stdout, 'write', () => {});154 stderrSpy = t.mock.method(process.stderr, 'write', () => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 155–158why, one step back
155 });
156157 test('when help requested then text is on stdout', () => {158 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 159why, one step back
159 program.exitOverride().addHelpText('before', 'text');

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

line 160why, one step back
160 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 161why, one step back
161 program.parse(['--help'], { from: 'user' });

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

lines 162–163why, one step back
162 });
163 assert.equal(stdoutSpy.mock.calls[0].arguments[0], 'text\n');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 164–167why, one step back
164 });
165166 test('when help for error then text is on stderr', () => {167 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 168why, one step back
168 program.exitOverride().addHelpText('before', 'text').command('sub');

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

line 169why, one step back
169 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 170why, one step back
170 program.parse([], { from: 'user' });

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

lines 171–172why, one step back
171 });
172 assert.equal(stderrSpy.mock.calls[0].arguments[0], 'text\n');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 173–175why, one step back
173 });
174175 test('when help requested then context.error is false', () => {

Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6

line 176why, one step back
176 let context;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 177why, one step back
177 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 178–180why, one step back
178 program.exitOverride().addHelpText('before', (contextParam) => {
179 context = contextParam;180 });

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

line 181why, one step back
181 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 182why, one step back
182 program.parse(['--help'], { from: 'user' });

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

lines 183–184why, one step back
183 });
184 assert.equal(context.error, false);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 185–187why, one step back
185 });
186187 test('when help for error then context.error is true', () => {

Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6

line 188why, one step back
188 let context;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 189–191why, one step back
189 const program = new commander.Command();
190 program191 .exitOverride()

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 192–194why, one step back
192 .addHelpText('before', (contextParam) => {
193 context = contextParam;194 })

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 195why, one step back
195 .command('sub');

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

line 196why, one step back
196 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 197why, one step back
197 program.parse([], { from: 'user' });

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

lines 198–199why, one step back
198 });
199 assert.equal(context.error, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 200–202why, one step back
200 });
201202 test('when help on program then context.command is program', () => {

Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6

line 203why, one step back
203 let context;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 204why, one step back
204 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 205–207why, one step back
205 program.exitOverride().addHelpText('before', (contextParam) => {
206 context = contextParam;207 });

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

line 208why, one step back
208 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 209why, one step back
209 program.parse(['--help'], { from: 'user' });

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

lines 210–211why, one step back
210 });
211 assert.equal(context.command, program);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 212–214why, one step back
212 });
213214 test('when help on subcommand and "before" subcommand then context.command is subcommand', () => {

Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6

line 215why, one step back
215 let context;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 216why, one step back
216 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 217–220why, one step back
217 program.exitOverride();
218 const sub = program.command('sub').addHelpText('before', (contextParam) => {219 context = contextParam;220 });

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

line 221why, one step back
221 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 222why, one step back
222 program.parse(['sub', '--help'], { from: 'user' });

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

lines 223–224why, one step back
223 });
224 assert.equal(context.command, sub);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 225–227why, one step back
225 });
226227 test('when help on subcommand and "beforeAll" on program then context.command is subcommand', () => {

Change initial variable values in test for better error messagesWee Bitbefore adoption401b0d6

line 228why, one step back
228 let context;

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 229why, one step back
229 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 230–232why, one step back
230 program.exitOverride().addHelpText('beforeAll', (contextParam) => {
231 context = contextParam;232 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 233why, one step back
233 const sub = program.command('sub');

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

line 234why, one step back
234 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 235why, one step back
235 program.parse(['sub', '--help'], { from: 'user' });

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

lines 236–237why, one step back
236 });
237 assert.equal(context.command, sub);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 238–239why, one step back
238 });
239});