Skip to content
Myr

command.positionalOptions.test.js

This file

Path

tests/command.positionalOptions.test.js

534 lines · 20.3 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–3why, one step back
2const { test, describe } = require('node:test');
3const assert = require('node:assert/strict');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 4–7why, one step back
4
5// The changes to parsing for positional options are subtle, and took extra care to work with6// implicit help and default commands. Lots of tests.7

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

lines 8–15why, one step back
8describe('positional options using Command.passThroughOptions() and Command.enablePositionalOptions()', () => {
9 describe('program with passThrough', () => {10 function makeProgram() {11 const program = new commander.Command();12 program.passThroughOptions();13 program.option('-d, --debug').argument('<args...>');14 return program;15 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 16why, one step back
16

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

lines 17–22why, one step back
17 test('when option before command-argument then option parsed', () => {
18 const program = makeProgram();19 program.parse(['--debug', 'arg'], { from: 'user' });20 assert.deepEqual(program.args, ['arg']);21 assert.equal(program.opts().debug, true);22 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 23why, one step back
23

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

lines 24–29why, one step back
24 test('when known option after command-argument then option passed through', () => {
25 const program = makeProgram();26 program.parse(['arg', '--debug'], { from: 'user' });27 assert.deepEqual(program.args, ['arg', '--debug']);28 assert.equal(program.opts().debug, undefined);29 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 30why, one step back
30

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

lines 31–35why, one step back
31 test('when unknown option after command-argument then option passed through', () => {
32 const program = makeProgram();33 program.parse(['arg', '--pass'], { from: 'user' });34 assert.deepEqual(program.args, ['arg', '--pass']);35 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 36why, one step back
36

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

lines 37–45why, one step back
37 test('when action handler and unknown option after command-argument then option passed through', (t) => {
38 const program = makeProgram();39 const mockAction = t.mock.fn();40 program.action(mockAction);41 program.parse(['arg', '--pass'], { from: 'user' });42 assert.equal(mockAction.mock.callCount(), 1);43 const callArgs = mockAction.mock.calls[0].arguments;44 assert.deepEqual(callArgs[0], ['arg', '--pass']);45 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 46why, one step back
46

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

lines 47–49why, one step back
47 test('when help option (without command-argument) then help called', (t) => {
48 const program = makeProgram();49 const mockHelp = t.mock.fn(() => '');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 50why, one step back
50

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

lines 51–58why, one step back
51 program.exitOverride().configureHelp({ formatHelp: mockHelp });
52 try {53 program.parse(['--help'], { from: 'user' });54 } catch (err) {55 /* empty */56 }57 assert.equal(mockHelp.mock.callCount(), 1);58 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 59why, one step back
59

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

lines 60–64why, one step back
60 test('when help option after command-argument then option passed through', () => {
61 const program = makeProgram();62 program.parse(['arg', '--help'], { from: 'user' });63 assert.deepEqual(program.args, ['arg', '--help']);64 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 65why, one step back
65

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

lines 66–71why, one step back
66 test('when version option after command-argument then option passed through', () => {
67 const program = makeProgram();68 program.version('1.2.3');69 program.parse(['arg', '--version'], { from: 'user' });70 assert.deepEqual(program.args, ['arg', '--version']);71 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 72–73why, one step back
72 });
73

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

line 74why, one step back
74 // -----------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 75why, one step back
75

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

lines 76–89why, one step back
76 describe('program with positionalOptions and subcommand', () => {
77 function makeProgram() {78 const program = new commander.Command();79 program80 .enablePositionalOptions()81 .option('-s, --shared <value>')82 .argument('<args...>');83 const sub = program84 .command('sub')85 .argument('[arg]')86 .option('-s, --shared <value>')87 .action(() => {}); // Not used, but normal to have action handler on subcommand.88 return { program, sub };89 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 90why, one step back
90

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

lines 91–95why, one step back
91 test('when global option before subcommand then global option parsed', () => {
92 const { program } = makeProgram();93 program.parse(['--shared', 'program', 'sub'], { from: 'user' });94 assert.equal(program.opts().shared, 'program');95 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 96why, one step back
96

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

lines 97–102why, one step back
97 test('when shared option after subcommand then parsed by subcommand', () => {
98 const { program, sub } = makeProgram();99 program.parse(['sub', '--shared', 'local'], { from: 'user' });100 assert.equal(sub.opts().shared, 'local');101 assert.equal(program.opts().shared, undefined);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–110why, one step back
104 test('when shared option after subcommand argument then parsed by subcommand', () => {
105 const { program, sub } = makeProgram();106 program.parse(['sub', 'arg', '--shared', 'local'], { from: 'user' });107 assert.equal(sub.opts().shared, 'local');108 assert.deepEqual(sub.args, ['arg']);109 assert.equal(program.opts().shared, undefined);110 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 111why, one step back
111

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

lines 112–118why, one step back
112 test('when shared option before and after subcommand then both parsed', () => {
113 const { program, sub } = makeProgram();114 program.parse(['--shared', 'program', 'sub', '--shared', 'local'], {115 from: 'user',116 });117 assert.equal(program.opts().shared, 'program');118 assert.equal(sub.opts().shared, 'local');

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 119why, one step back
119 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 120why, one step back
120

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

lines 121–130why, one step back
121 describe('help', () => {
122 const cases = [123 { args: [], programHelp: 1, subHelp: 0 },124 { args: ['sub'], programHelp: 0, subHelp: 0 },125 { args: ['--help'], programHelp: 1, subHelp: 0 },126 { args: ['sub', '--help'], programHelp: 0, subHelp: 1 },127 { args: ['sub', 'foo', '--help'], programHelp: 0, subHelp: 1 },128 { args: ['help'], programHelp: 1, subHelp: 0 },129 { args: ['help', 'sub'], programHelp: 0, subHelp: 1 },130 ];

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 131why, one step back
131

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

lines 132–138why, one step back
132 for (const { args, programHelp, subHelp } of cases) {
133 test(`when user args ${JSON.stringify(args)} then program/sub help called ${programHelp}/${subHelp}`, (t) => {134 const { program, sub } = makeProgram();135 const mockProgramHelp = t.mock.fn();136 program.exitOverride().configureHelp({ formatHelp: mockProgramHelp });137 const mockSubHelp = t.mock.fn();138 sub.exitOverride().configureHelp({ formatHelp: mockSubHelp });

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

line 139why, one step back
139

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

lines 140–149why, one step back
140 try {
141 program.parse(args, { from: 'user' });142 } catch (err) {143 /* empty */144 }145 assert.equal(mockProgramHelp.mock.callCount(), programHelp);146 assert.equal(mockSubHelp.mock.callCount(), subHelp);147 });148 }149 });

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

line 150why, one step back
150 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 151why, one step back
151

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

line 152why, one step back
152 // ---------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 153why, one step back
153

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

lines 154–170why, one step back
154 describe('program with positionalOptions and default subcommand (called sub)', () => {
155 function makeProgram() {156 const program = new commander.Command();157 program158 .enablePositionalOptions()159 .option('-s, --shared')160 .option('-g, --global')161 .argument('<args...>');162 const sub = program163 .command('sub', { isDefault: true })164 .argument('[args...]')165 .option('-s, --shared')166 .option('-d, --default')167 .action(() => {}); // Not used, but normal to have action handler on subcommand.168 program.command('another'); // Not used, but normal to have more than one subcommand if have a default.169 return { program, sub };170 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 171why, one step back
171

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

lines 172–176why, one step back
172 test('when program option before sub option then program option read by program', () => {
173 const { program } = makeProgram();174 program.parse(['--global', '--default'], { from: 'user' });175 assert.equal(program.opts().global, true);176 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 177why, one step back
177

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

lines 178–182why, one step back
178 test('when program option before sub option then sub option read by sub', () => {
179 const { program, sub } = makeProgram();180 program.parse(['--global', '--default'], { from: 'user' });181 assert.equal(sub.opts().default, true);182 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 183why, one step back
183

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

lines 184–188why, one step back
184 test('when shared option before sub argument then option read by program', () => {
185 const { program } = makeProgram();186 program.parse(['--shared', 'foo'], { from: 'user' });187 assert.equal(program.opts().shared, true);188 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 189why, one step back
189

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

lines 190–194why, one step back
190 test('when shared option after sub argument then option read by sub', () => {
191 const { program, sub } = makeProgram();192 program.parse(['foo', '--shared'], { from: 'user' });193 assert.equal(sub.opts().shared, true);194 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 195why, one step back
195

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

lines 196–201why, one step back
196 describe('help', () => {
197 const cases = [198 { args: [], programHelp: 0, subHelp: 0 },199 { args: ['--help'], programHelp: 1, subHelp: 0 },200 { args: ['help'], programHelp: 1, subHelp: 0 },201 ];

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 202why, one step back
202

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

lines 203–209why, one step back
203 for (const { args, programHelp, subHelp } of cases) {
204 test(`when user args ${JSON.stringify(args)} then program/sub help called ${programHelp}/${subHelp}`, (t) => {205 const { program, sub } = makeProgram();206 const mockProgramHelp = t.mock.fn();207 program.exitOverride().configureHelp({ formatHelp: mockProgramHelp });208 const mockSubHelp = t.mock.fn();209 sub.exitOverride().configureHelp({ formatHelp: mockSubHelp });

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

line 210why, one step back
210

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

lines 211–220why, one step back
211 try {
212 program.parse(args, { from: 'user' });213 } catch (err) {214 /* empty */215 }216 assert.equal(mockProgramHelp.mock.callCount(), programHelp);217 assert.equal(mockSubHelp.mock.callCount(), subHelp);218 });219 }220 });

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

line 221why, one step back
221 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 222why, one step back
222

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

line 223why, one step back
223 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 224why, one step back
224

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

lines 225–240why, one step back
225 describe('subcommand with passThrough', () => {
226 function makeProgram() {227 const program = new commander.Command();228 program229 .enablePositionalOptions()230 .option('-s, --shared <value>')231 .argument('<args...>');232 const sub = program233 .command('sub')234 .passThroughOptions()235 .argument('[args...]')236 .option('-s, --shared <value>')237 .option('-d, --debug')238 .action(() => {}); // Not used, but normal to have action handler on subcommand.239 return { program, sub };240 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 241why, one step back
241

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

lines 242–247why, one step back
242 test('when option before command-argument then option parsed', () => {
243 const { program, sub } = makeProgram();244 program.parse(['sub', '--debug', 'arg'], { from: 'user' });245 assert.deepEqual(sub.args, ['arg']);246 assert.equal(sub.opts().debug, true);247 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 248why, one step back
248

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

lines 249–254why, one step back
249 test('when known option after command-argument then option passed through', () => {
250 const { program, sub } = makeProgram();251 program.parse(['sub', 'arg', '--debug'], { from: 'user' });252 assert.deepEqual(sub.args, ['arg', '--debug']);253 assert.equal(sub.opts().debug, undefined);254 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 255why, one step back
255

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

lines 256–260why, one step back
256 test('when unknown option after command-argument then option passed through', () => {
257 const { program, sub } = makeProgram();258 program.parse(['sub', 'arg', '--pass'], { from: 'user' });259 assert.deepEqual(sub.args, ['arg', '--pass']);260 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 261why, one step back
261

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

lines 262–270why, one step back
262 test('when action handler and unknown option after command-argument then option passed through', (t) => {
263 const { program, sub } = makeProgram();264 const mockAction = t.mock.fn();265 sub.action(mockAction);266 program.parse(['sub', 'arg', '--pass'], { from: 'user' });267 assert.equal(mockAction.mock.callCount(), 1);268 const callArgs = mockAction.mock.calls[0].arguments;269 assert.deepEqual(callArgs[0], ['arg', '--pass']);270 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 271why, one step back
271

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

lines 272–276why, one step back
272 test('when help option after command-argument then option passed through', () => {
273 const { program, sub } = makeProgram();274 program.parse(['sub', 'arg', '--help'], { from: 'user' });275 assert.deepEqual(sub.args, ['arg', '--help']);276 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 277why, one step back
277

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

lines 278–283why, one step back
278 test('when version option after command-argument then option passed through', () => {
279 const { program, sub } = makeProgram();280 program.version('1.2.3');281 program.parse(['sub', 'arg', '--version'], { from: 'user' });282 assert.deepEqual(sub.args, ['arg', '--version']);283 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 284why, one step back
284

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

lines 285–294why, one step back
285 test('when shared option before sub and after sub and after sub parameter then all three parsed', () => {
286 const { program, sub } = makeProgram();287 program.parse(288 ['--shared=global', 'sub', '--shared=local', 'arg', '--shared'],289 { from: 'user' },290 );291 assert.equal(program.opts().shared, 'global');292 assert.equal(sub.opts().shared, 'local');293 assert.deepEqual(sub.args, ['arg', '--shared']);294 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 295–296why, one step back
295 });
296

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

line 297why, one step back
297 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 298why, one step back
298

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

lines 299–310why, one step back
299 describe('default command with passThrough', () => {
300 function makeProgram() {301 const program = new commander.Command();302 program.enablePositionalOptions();303 const sub = program304 .command('sub', { isDefault: true })305 .passThroughOptions()306 .argument('[args...]')307 .option('-d, --debug')308 .action(() => {}); // Not used, but normal to have action handler on subcommand.309 return { program, sub };310 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 311why, one step back
311

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

lines 312–317why, one step back
312 test('when option before command-argument then option parsed', () => {
313 const { program, sub } = makeProgram();314 program.parse(['--debug', 'arg'], { from: 'user' });315 assert.deepEqual(sub.args, ['arg']);316 assert.equal(sub.opts().debug, true);317 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 318why, one step back
318

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

lines 319–324why, one step back
319 test('when known option after command-argument then option passed through', () => {
320 const { program, sub } = makeProgram();321 program.parse(['arg', '--debug'], { from: 'user' });322 assert.deepEqual(sub.args, ['arg', '--debug']);323 assert.equal(sub.opts().debug, undefined);324 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 325why, one step back
325

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

lines 326–330why, one step back
326 test('when unknown option after command-argument then option passed through', () => {
327 const { program, sub } = makeProgram();328 program.parse(['arg', '--pass'], { from: 'user' });329 assert.deepEqual(sub.args, ['arg', '--pass']);330 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 331why, one step back
331

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

lines 332–340why, one step back
332 test('when action handler and unknown option after command-argument then option passed through', (t) => {
333 const { program, sub } = makeProgram();334 const mockAction = t.mock.fn();335 sub.action(mockAction);336 program.parse(['arg', '--pass'], { from: 'user' });337 assert.equal(mockAction.mock.callCount(), 1);338 const callArgs = mockAction.mock.calls[0].arguments;339 assert.deepEqual(callArgs[0], ['arg', '--pass']);340 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 341–342why, one step back
341 });
342

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

line 343why, one step back
343 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 344why, one step back
344

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

lines 345–358why, one step back
345 describe('program with action handler and positionalOptions and subcommand', () => {
346 function makeProgram() {347 const program = new commander.Command();348 program349 .enablePositionalOptions()350 .option('-g, --global')351 .argument('<args...>')352 .action(() => {});353 const sub = program354 .command('sub')355 .argument('[arg]')356 .action(() => {});357 return { program, sub };358 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 359why, one step back
359

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

lines 360–364why, one step back
360 test('when global option before parameter then global option parsed', () => {
361 const { program } = makeProgram();362 program.parse(['--global', 'foo'], { from: 'user' });363 assert.equal(program.opts().global, true);364 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 365why, one step back
365

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

lines 366–370why, one step back
366 test('when global option after parameter then global option parsed', () => {
367 const { program } = makeProgram();368 program.parse(['foo', '--global'], { from: 'user' });369 assert.equal(program.opts().global, true);370 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 371why, one step back
371

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

lines 372–376why, one step back
372 test('when global option after parameter with same name as subcommand then global option parsed', () => {
373 const { program } = makeProgram();374 program.parse(['foo', 'sub', '--global'], { from: 'user' });375 assert.equal(program.opts().global, true);376 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 377–378why, one step back
377 });
378

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

line 379why, one step back
379 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 380why, one step back
380

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

lines 381–384why, one step back
381 describe('broken passThrough', () => {
382 test('when program not positional and turn on passThroughOptions in subcommand then error', () => {383 const program = new commander.Command();384 const sub = program.command('sub');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 385why, one step back
385

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

lines 386–388why, one step back
386 assert.throws(() => {
387 sub.passThroughOptions();388 });

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

line 389why, one step back
389 });

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 390why, one step back
390

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

lines 391–393why, one step back
391 test('when program not positional and add subcommand with passThroughOptions then error', () => {
392 const program = new commander.Command();393 const sub = new commander.Command('sub').passThroughOptions();

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 394why, one step back
394

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

lines 395–397why, one step back
395 assert.throws(() => {
396 program.addCommand(sub);397 });

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

line 398why, one step back
398 });

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 399why, one step back
399 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 400why, one step back
400

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

line 401why, one step back
401 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 402why, one step back
402

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

lines 403–418why, one step back
403 describe('program with action handler and passThrough and subcommand', () => {
404 function makeProgram() {405 const program = new commander.Command();406 program407 .passThroughOptions()408 .option('-g, --global')409 .argument('<args...>')410 .action(() => {});411 const sub = program412 .command('sub')413 .argument('[arg]')414 .option('-g, --group')415 .option('-d, --debug')416 .action(() => {});417 return { program, sub };418 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 419why, one step back
419

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

lines 420–424why, one step back
420 test('when global option before parameter then global option parsed', () => {
421 const { program } = makeProgram();422 program.parse(['--global', 'foo'], { from: 'user' });423 assert.equal(program.opts().global, true);424 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 425why, one step back
425

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

lines 426–430why, one step back
426 test('when global option after parameter then passed through', () => {
427 const { program } = makeProgram();428 program.parse(['foo', '--global'], { from: 'user' });429 assert.deepEqual(program.args, ['foo', '--global']);430 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 431why, one step back
431

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

lines 432–436why, one step back
432 test('when subcommand option after subcommand then option parsed', () => {
433 const { program, sub } = makeProgram();434 program.parse(['sub', '--debug'], { from: 'user' });435 assert.equal(sub.opts().debug, true);436 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 437why, one step back
437

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

lines 438–444why, one step back
438 // This is somewhat of a side-effect of supporting previous test.
439 test('when shared option after subcommand then parsed by subcommand', () => {440 const { program, sub } = makeProgram();441 program.parse(['sub', '-g'], { from: 'user' });442 assert.equal(sub.opts().group, true);443 assert.equal(program.opts().global, undefined);444 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 445–446why, one step back
445 });
446

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

line 447why, one step back
447 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 448why, one step back
448

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

lines 449–453why, one step back
449 describe('program with allowUnknownOption', () => {
450 test('when passThroughOptions and unknown option then arguments from unknown passed through', () => {451 const program = new commander.Command();452 program.passThroughOptions().allowUnknownOption().option('--debug');453 program.argument('[args...]');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 454why, one step back
454

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

lines 455–457why, one step back
455 program.parse(['--unknown', '--debug'], { from: 'user' });
456 assert.deepEqual(program.args, ['--unknown', '--debug']);457 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 458why, one step back
458

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

lines 459–462why, one step back
459 test('when positionalOptions and unknown option then known options then known option parsed', () => {
460 const program = new commander.Command();461 program.enablePositionalOptions().allowUnknownOption().option('--debug');462 program.argument('[args...]');

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 463why, one step back
463

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

lines 464–467why, one step back
464 program.parse(['--unknown', '--debug'], { from: 'user' });
465 assert.equal(program.opts().debug, true);466 assert.deepEqual(program.args, ['--unknown']);467 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 468–469why, one step back
468 });
469

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

line 470why, one step back
470 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 471why, one step back
471

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

lines 472–477why, one step back
472 describe('passThroughOptions(xxx) and option after command-argument', () => {
473 function makeProgram() {474 const program = new commander.Command();475 program.option('-d, --debug').argument('<args...>');476 return program;477 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 478why, one step back
478

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

lines 479–484why, one step back
479 test('when passThroughOptions() then option passed through', () => {
480 const program = makeProgram();481 program.passThroughOptions();482 program.parse(['foo', '--debug'], { from: 'user' });483 assert.deepEqual(program.args, ['foo', '--debug']);484 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 485why, one step back
485

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

lines 486–491why, one step back
486 test('when passThroughOptions(true) then option passed through', () => {
487 const program = makeProgram();488 program.passThroughOptions(true);489 program.parse(['foo', '--debug'], { from: 'user' });490 assert.deepEqual(program.args, ['foo', '--debug']);491 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 492why, one step back
492

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

lines 493–499why, one step back
493 test('when passThroughOptions(false) then option parsed', () => {
494 const program = makeProgram();495 program.passThroughOptions(false);496 program.parse(['foo', '--debug'], { from: 'user' });497 assert.deepEqual(program.args, ['foo']);498 assert.equal(program.opts().debug, true);499 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 500–501why, one step back
500 });
501

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

line 502why, one step back
502 // ------------------------------------------------------------------------------

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 503why, one step back
503

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

lines 504–510why, one step back
504 describe('enablePositionalOptions(xxx) and shared option after subcommand', () => {
505 function makeProgram() {506 const program = new commander.Command();507 program.option('-d, --debug');508 const sub = program.command('sub').option('-d, --debug');509 return { program, sub };510 }

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 511why, one step back
511

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

lines 512–517why, one step back
512 test('when enablePositionalOptions() then option parsed by subcommand', () => {
513 const { program, sub } = makeProgram();514 program.enablePositionalOptions();515 program.parse(['sub', '--debug'], { from: 'user' });516 assert.equal(sub.opts().debug, true);517 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 518why, one step back
518

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

lines 519–524why, one step back
519 test('when enablePositionalOptions(true) then option parsed by subcommand', () => {
520 const { program, sub } = makeProgram();521 program.enablePositionalOptions(true);522 program.parse(['sub', '--debug'], { from: 'user' });523 assert.equal(sub.opts().debug, true);524 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

line 525why, one step back
525

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

lines 526–532why, one step back
526 test('when enablePositionalOptions(false) then option parsed by program', () => {
527 const { program, sub } = makeProgram();528 program.enablePositionalOptions(false);529 program.parse(['sub', '--debug'], { from: 'user' });530 assert.equal(sub.opts().debug, undefined);531 assert.equal(program.opts().debug, true);532 });

update chinese readme (#1727)wenjiebefore adoptionb2842dc

lines 533–534why, one step back
533 });
534});