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 fileTake it
The walk stopped after 200 commits: lines older than b2842dc point at it.
update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 1why, one step back1const commander = require('../');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 2–3why, one step back2const { test, describe } = require('node:test');3const assert = require('node:assert/strict');update chinese readme (#1727)wenjiebefore adoptionb2842dc
lines 4–7why, one step back45// The changes to parsing for positional options are subtle, and took extra care to work with6// implicit help and default commands. Lots of tests.7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–15why, one step back8describe('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 back16Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 17–22why, one step back17 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 back23Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 24–29why, one step back24 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 back30Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 31–35why, one step back31 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 back36Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 37–45why, one step back37 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 back46Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 47–49why, one step back47 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 back50Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 51–58why, one step back51 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 back59Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 60–64why, one step back60 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 back65Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 66–71why, one step back66 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 back72 });73Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 74why, one step back74 // -----------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 75why, one step back75Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 76–89why, one step back76 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 back90Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 91–95why, one step back91 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 back96Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 97–102why, one step back97 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 back103Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 104–110why, one step back104 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 back111Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 112–118why, one step back112 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 back119 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 120why, one step back120Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 121–130why, one step back121 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 back131Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 132–138why, one step back132 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 back139Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 140–149why, one step back140 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 back150 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 151why, one step back151Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 152why, one step back152 // ---------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 153why, one step back153Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 154–170why, one step back154 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 back171Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 172–176why, one step back172 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 back177Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 178–182why, one step back178 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 back183Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 184–188why, one step back184 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 back189Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 190–194why, one step back190 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 back195Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 196–201why, one step back196 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 back202Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 203–209why, one step back203 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 back210Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 211–220why, one step back211 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 back221 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 222why, one step back222Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 223why, one step back223 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 224why, one step back224Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 225–240why, one step back225 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 back241Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 242–247why, one step back242 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 back248Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 249–254why, one step back249 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 back255Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 256–260why, one step back256 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 back261Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 262–270why, one step back262 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 back271Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 272–276why, one step back272 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 back277Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 278–283why, one step back278 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 back284Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 285–294why, one step back285 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 back295 });296Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 297why, one step back297 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 298why, one step back298Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 299–310why, one step back299 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 back311Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 312–317why, one step back312 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 back318Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 319–324why, one step back319 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 back325Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 326–330why, one step back326 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 back331Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 332–340why, one step back332 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 back341 });342Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 343why, one step back343 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 344why, one step back344Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 345–358why, one step back345 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 back359Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 360–364why, one step back360 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 back365Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 366–370why, one step back366 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 back371Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 372–376why, one step back372 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 back377 });378Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 379why, one step back379 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 380why, one step back380Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 381–384why, one step back381 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 back385Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 386–388why, one step back386 assert.throws(() => {387 sub.passThroughOptions();388 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 389why, one step back389 });Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 390why, one step back390Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 391–393why, one step back391 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 back394Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 395–397why, one step back395 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 back398 });Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 399why, one step back399 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 400why, one step back400Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 401why, one step back401 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 402why, one step back402Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 403–418why, one step back403 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 back419Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 420–424why, one step back420 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 back425Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 426–430why, one step back426 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 back431Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 432–436why, one step back432 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 back437Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 438–444why, one step back438 // 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 back445 });446Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 447why, one step back447 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 448why, one step back448Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 449–453why, one step back449 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 back454Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 455–457why, one step back455 program.parse(['--unknown', '--debug'], { from: 'user' });456 assert.deepEqual(program.args, ['--unknown', '--debug']);457 });update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 458why, one step back458Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 459–462why, one step back459 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 back463Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 464–467why, one step back464 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 back468 });469Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 470why, one step back470 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 471why, one step back471Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 472–477why, one step back472 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 back478Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 479–484why, one step back479 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 back485Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 486–491why, one step back486 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 back492Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 493–499why, one step back493 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 back500 });501Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 502why, one step back502 // ------------------------------------------------------------------------------update chinese readme (#1727)wenjiebefore adoptionb2842dc
line 503why, one step back503Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 504–510why, one step back504 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 back511Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 512–517why, one step back512 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 back518Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 519–524why, one step back519 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 back525Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 526–532why, one step back526 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 back533 });534});