command.argumentVariations.test.js
This file
Path
tests/command.argumentVariations.test.js
135 lines · 4.0 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than c1472bc point at it.
Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 1–5why, one step back1const commander = require('../');23// Do some low-level checks that the multiple ways of specifying command arguments produce same internal result,4// and not exhaustively testing all methods elsewhere.5Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 6–18why, one step back6test.each(getSingleArgCases('<explicit-required>'))(7 'when add "<arg>" using %s then argument required',8 (methodName, cmd) => {9 const argument = cmd.registeredArguments[0];10 const expectedShape = {11 _name: 'explicit-required',12 required: true,13 variadic: false,14 description: '',15 };16 expect(argument).toEqual(expectedShape);17 },18);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
line 19why, one step back19Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 20–32why, one step back20test.each(getSingleArgCases('implicit-required'))(21 'when add "arg" using %s then argument required',22 (methodName, cmd) => {23 const argument = cmd.registeredArguments[0];24 const expectedShape = {25 _name: 'implicit-required',26 required: true,27 variadic: false,28 description: '',29 };30 expect(argument).toEqual(expectedShape);31 },32);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
line 33why, one step back33Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 34–46why, one step back34test.each(getSingleArgCases('[optional]'))(35 'when add "[arg]" using %s then argument optional',36 (methodName, cmd) => {37 const argument = cmd.registeredArguments[0];38 const expectedShape = {39 _name: 'optional',40 required: false,41 variadic: false,42 description: '',43 };44 expect(argument).toEqual(expectedShape);45 },46);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
line 47why, one step back47Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 48–60why, one step back48test.each(getSingleArgCases('<explicit-required...>'))(49 'when add "<arg...>" using %s then argument required and variadic',50 (methodName, cmd) => {51 const argument = cmd.registeredArguments[0];52 const expectedShape = {53 _name: 'explicit-required',54 required: true,55 variadic: true,56 description: '',57 };58 expect(argument).toEqual(expectedShape);59 },60);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
line 61why, one step back61Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 62–74why, one step back62test.each(getSingleArgCases('implicit-required...'))(63 'when add "arg..." using %s then argument required and variadic',64 (methodName, cmd) => {65 const argument = cmd.registeredArguments[0];66 const expectedShape = {67 _name: 'implicit-required',68 required: true,69 variadic: true,70 description: '',71 };72 expect(argument).toEqual(expectedShape);73 },74);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
line 75why, one step back75Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 76–88why, one step back76test.each(getSingleArgCases('[optional...]'))(77 'when add "[arg...]" using %s then argument optional and variadic',78 (methodName, cmd) => {79 const argument = cmd.registeredArguments[0];80 const expectedShape = {81 _name: 'optional',82 required: false,83 variadic: true,84 description: '',85 };86 expect(argument).toEqual(expectedShape);87 },88);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 89–93why, one step back8990function getSingleArgCases(arg) {91 return [92 ['.arguments', new commander.Command().arguments(arg)],93 ['.argument', new commander.Command().argument(arg)],Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 94–100why, one step back94 [95 '.addArgument',96 new commander.Command('add-argument').addArgument(97 new commander.Argument(arg),98 ),99 ],100 ['.command', new commander.Command().command(`command ${arg}`)],Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 101–103why, one step back101 ];102}103Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 104–110why, one step back104test.each(getMultipleArgCases('<first>', '[second]'))(105 'when add two arguments using %s then two arguments',106 (methodName, cmd) => {107 expect(cmd.registeredArguments[0].name()).toEqual('first');108 expect(cmd.registeredArguments[1].name()).toEqual('second');109 },110);Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 111–115why, one step back111112function getMultipleArgCases(arg1, arg2) {113 return [114 ['.arguments', new commander.Command().arguments(`${arg1} ${arg2}`)],115 ['.argument', new commander.Command().argument(arg1).argument(arg2)],Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 116–122why, one step back116 [117 '.addArgument',118 new commander.Command('add-argument')119 .addArgument(new commander.Argument(arg1))120 .addArgument(new commander.Argument(arg2)),121 ],122 ['.command', new commander.Command().command(`command ${arg1} ${arg2}`)],Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 123–132why, one step back123 ];124}125126test('when add arguments using multiple methods then all added', () => {127 // This is not a key use case, but explicitly test that additive behaviour.128 const program = new commander.Command();129 const cmd = program.command('sub <arg1> <arg2>');130 cmd.arguments('<arg3> <arg4>');131 cmd.argument('<arg5>');132 cmd.addArgument(new commander.Argument('arg6'));Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 133why, one step back133 const argNames = cmd.registeredArguments.map((arg) => arg.name());Tidy up some old examples (#1604)John Geebefore adoptionc1472bc
lines 134–135why, one step back134 expect(argNames).toEqual(['arg1', 'arg2', 'arg3', 'arg4', 'arg5', 'arg6']);135});