Skip to content
Myr

command.argumentVariations.test.js

This file

Path

tests/command.argumentVariations.test.js

135 lines · 4.9 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 cc2db5b point at it.

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

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');

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

lines 4–7why, one step back
4
5// Do some low-level checks that the multiple ways of specifying command arguments produce same internal result,6// and not exhaustively testing all methods elsewhere.7

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

lines 8–17why, one step back
8describe('Command arguments added using different methods', () => {
9 describe('when add "<arg>" then argument required', () => {10 getSingleArgCases('<explicit-required>').forEach(([methodName, cmd]) => {11 test(`using ${methodName}`, () => {12 const argument = cmd.registeredArguments[0];13 assert.equal(argument._name, 'explicit-required');14 assert.equal(argument.required, true);15 assert.equal(argument.variadic, false);16 assert.equal(argument.description, '');17 });

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

lines 18–19why, one step back
18 });
19 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 20why, one step back
20

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

lines 21–29why, one step back
21 describe('when add "arg" then argument required', () => {
22 getSingleArgCases('implicit-required').forEach(([methodName, cmd]) => {23 test(`using ${methodName}`, () => {24 const argument = cmd.registeredArguments[0];25 assert.equal(argument._name, 'implicit-required');26 assert.equal(argument.required, true);27 assert.equal(argument.variadic, false);28 assert.equal(argument.description, '');29 });

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

lines 30–31why, one step back
30 });
31 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 32why, one step back
32

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

lines 33–41why, one step back
33 describe('when add "[arg]" then argument optional', () => {
34 getSingleArgCases('[optional]').forEach(([methodName, cmd]) => {35 test(`using ${methodName}`, () => {36 const argument = cmd.registeredArguments[0];37 assert.equal(argument._name, 'optional');38 assert.equal(argument.required, false);39 assert.equal(argument.variadic, false);40 assert.equal(argument.description, '');41 });

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

lines 42–43why, one step back
42 });
43 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 44why, one step back
44

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

lines 45–53why, one step back
45 describe('when add "<arg...>" then argument required and variadic', () => {
46 getSingleArgCases('<explicit-required...>').forEach(([methodName, cmd]) => {47 test(`using ${methodName}`, () => {48 const argument = cmd.registeredArguments[0];49 assert.equal(argument._name, 'explicit-required');50 assert.equal(argument.required, true);51 assert.equal(argument.variadic, true);52 assert.equal(argument.description, '');53 });

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

lines 54–55why, one step back
54 });
55 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 56why, one step back
56

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

lines 57–65why, one step back
57 describe('when add "arg..." then argument required and variadic', () => {
58 getSingleArgCases('implicit-required...').forEach(([methodName, cmd]) => {59 test(`using ${methodName}`, () => {60 const argument = cmd.registeredArguments[0];61 assert.equal(argument._name, 'implicit-required');62 assert.equal(argument.required, true);63 assert.equal(argument.variadic, true);64 assert.equal(argument.description, '');65 });

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

lines 66–67why, one step back
66 });
67 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 68why, one step back
68

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

lines 69–77why, one step back
69 describe('when add "[arg...]" then argument optional and variadic', () => {
70 getSingleArgCases('[optional...]').forEach(([methodName, cmd]) => {71 test(`using ${methodName}`, () => {72 const argument = cmd.registeredArguments[0];73 assert.equal(argument._name, 'optional');74 assert.equal(argument.required, false);75 assert.equal(argument.variadic, true);76 assert.equal(argument.description, '');77 });

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

lines 78–79why, one step back
78 });
79 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 80why, one step back
80

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

lines 81–93why, one step back
81 function getSingleArgCases(arg) {
82 return [83 ['.arguments', new commander.Command().arguments(arg)],84 ['.argument', new commander.Command().argument(arg)],85 [86 '.addArgument',87 new commander.Command('add-argument').addArgument(88 new commander.Argument(arg),89 ),90 ],91 ['.command', new commander.Command().command(`command ${arg}`)],92 ];93 }

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 94why, one step back
94

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

lines 95–100why, one step back
95 describe('when add two arguments then two arguments', () => {
96 getMultipleArgCases('<first>', '[second]').forEach(([methodName, cmd]) => {97 test(`using ${methodName}`, () => {98 assert.equal(cmd.registeredArguments[0].name(), 'first');99 assert.equal(cmd.registeredArguments[1].name(), 'second');100 });

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

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

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 103why, one step back
103

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

lines 104–116why, one step back
104 function getMultipleArgCases(arg1, arg2) {
105 return [106 ['.arguments', new commander.Command().arguments(`${arg1} ${arg2}`)],107 ['.argument', new commander.Command().argument(arg1).argument(arg2)],108 [109 '.addArgument',110 new commander.Command('add-argument')111 .addArgument(new commander.Argument(arg1))112 .addArgument(new commander.Argument(arg2)),113 ],114 ['.command', new commander.Command().command(`command ${arg1} ${arg2}`)],115 ];116 }

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 117why, one step back
117

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

lines 118–134why, one step back
118 test('when add arguments using multiple methods then all added', () => {
119 // This is not a key use case, but explicitly test that additive behaviour.120 const program = new commander.Command();121 const cmd = program.command('sub <arg1> <arg2>');122 cmd.arguments('<arg3> <arg4>');123 cmd.argument('<arg5>');124 cmd.addArgument(new commander.Argument('arg6'));125 const argNames = cmd.registeredArguments.map((arg) => arg.name());126 assert.deepEqual(argNames, [127 'arg1',128 'arg2',129 'arg3',130 'arg4',131 'arg5',132 'arg6',133 ]);134 });

Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b

line 135why, one step back
135});