options.variadic.test.js
This file
Path
tests/options.variadic.test.js
191 lines · 6.7 KiB · JavaScript
Last changed by
Merge from develop into release/15.x (with minor conflicts and test migrations)John Geebefore adoption26e3ba3
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–4why, one step back1import * as commander from '../index.js';2import { createTestCommand } from './testHelpers.js';3import { test, describe } from 'node:test';4import assert from 'node:assert/strict';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 5why, one step back5Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 6–10why, one step back6describe('variadic options', () => {7 describe('variadic option with required option-argument', () => {8 test('when variadic with value missing then error', () => {9 const program = createTestCommand();10 program.option('-r,--required <value...>');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 11why, one step back11Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 12–14why, one step back12 assert.throws(() => {13 program.parse(['--required'], { from: 'user' });14 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 15why, one step back15 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 16why, one step back16Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 17–19why, one step back17 test('when variadic with one value then set in array', () => {18 const program = new commander.Command();19 program.option('-r,--required <value...>');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 20why, one step back20Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 21–23why, one step back21 program.parse(['--required', 'one'], { from: 'user' });22 assert.deepEqual(program.opts().required, ['one']);23 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 24why, one step back24Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 25–27why, one step back25 test('when variadic with two values then set in array', () => {26 const program = new commander.Command();27 program.option('-r,--required <value...>');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 28why, one step back28Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 29–31why, one step back29 program.parse(['--required', 'one', 'two'], { from: 'user' });30 assert.deepEqual(program.opts().required, ['one', 'two']);31 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 32why, one step back32Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 33–35why, one step back33 test('when variadic with repeated values then set in array', () => {34 const program = new commander.Command();35 program.option('-r,--required <value...>');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 36why, one step back36Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 37–41why, one step back37 program.parse(['--required', 'one', '--required', 'two'], {38 from: 'user',39 });40 assert.deepEqual(program.opts().required, ['one', 'two']);41 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 42why, one step back42Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 43–50why, one step back43 test('when variadic used with choices and one value then set in array', () => {44 const program = new commander.Command();45 program.addOption(46 new commander.Option('-r,--required <value...>').choices([47 'one',48 'two',49 ]),50 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 51why, one step back51Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 52–54why, one step back52 program.parse(['--required', 'one'], { from: 'user' });53 assert.deepEqual(program.opts().required, ['one']);54 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 55why, one step back55Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 56–63why, one step back56 test('when variadic used with choices and two values then set in array', () => {57 const program = new commander.Command();58 program.addOption(59 new commander.Option('-r,--required <value...>').choices([60 'one',61 'two',62 ]),63 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 64why, one step back64Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 65–67why, one step back65 program.parse(['--required', 'one', 'two'], { from: 'user' });66 assert.deepEqual(program.opts().required, ['one', 'two']);67 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 68why, one step back68Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 69–71why, one step back69 test('when variadic with short combined argument then not variadic', () => {70 const program = new commander.Command();71 program.option('-r,--required <value...>').argument('[arg]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 72why, one step back72Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 73–75why, one step back73 program.parse(['-rone', 'operand'], { from: 'user' });74 assert.deepEqual(program.opts().required, ['one']);75 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 76why, one step back76Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 77–79why, one step back77 test('when variadic with long combined argument then not variadic', () => {78 const program = new commander.Command();79 program.option('-r,--required <value...>').argument('[arg]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 80why, one step back80Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 81–83why, one step back81 program.parse(['--required=one', 'operand'], { from: 'user' });82 assert.deepEqual(program.opts().required, ['one']);83 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 84why, one step back84Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 85–90why, one step back85 test('when variadic with value followed by option then option not eaten', () => {86 const program = new commander.Command();87 program88 .option('-r,--required <value...>')89 .option('-f, --flag')90 .argument('[arg]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 91why, one step back91Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 92–96why, one step back92 program.parse(['-r', 'one', '-f'], { from: 'user' });93 const opts = program.opts();94 assert.deepEqual(opts.required, ['one']);95 assert.equal(opts.flag, true);96 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 97why, one step back97Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 98–104why, one step back98 test('when variadic with no value and default then set to default', () => {99 const program = new commander.Command();100 program.option(101 '-r,--required <value...>',102 'variadic description',103 'default',104 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 105why, one step back105Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 106–108why, one step back106 program.parse([], { from: 'user' });107 assert.equal(program.opts().required, 'default');108 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 109why, one step back109Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 110–116why, one step back110 test('when variadic with coercion then coercion sets value', () => {111 const program = new commander.Command();112 program.option(113 '-r,--required <value...>',114 'variadic description',115 parseFloat,116 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 117why, one step back117Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 118–121why, one step back118 // variadic processing reads the multiple values, but up to custom coercion what it does.119 program.parse(['--required', '1e2', '1e3'], { from: 'user' });120 assert.equal(program.opts().required, 1000);121 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 122–123why, one step back122 });123Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 124–128why, one step back124 // Not retesting everything, but do some tests on variadic with optional125 describe('variadic option with optional option-argument', () => {126 test('when variadic not specified then value undefined', () => {127 const program = new commander.Command();128 program.option('-o,--optional [value...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 129why, one step back129Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 130–132why, one step back130 program.parse([], { from: 'user' });131 assert.equal(program.opts().optional, undefined);132 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 133why, one step back133Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 134–136why, one step back134 test('when variadic used as boolean flag then value true', () => {135 const program = new commander.Command();136 program.option('-o,--optional [value...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 137why, one step back137Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 138–140why, one step back138 program.parse(['--optional'], { from: 'user' });139 assert.equal(program.opts().optional, true);140 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 141why, one step back141Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 142–144why, one step back142 test('when variadic with one value then set in array', () => {143 const program = new commander.Command();144 program.option('-o,--optional [value...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 145why, one step back145Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 146–148why, one step back146 program.parse(['--optional', 'one'], { from: 'user' });147 assert.deepEqual(program.opts().optional, ['one']);148 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 149why, one step back149Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 150–152why, one step back150 test('when variadic with two values then set in array', () => {151 const program = new commander.Command();152 program.option('-o,--optional [value...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 153why, one step back153Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 154–156why, one step back154 program.parse(['--optional', 'one', 'two'], { from: 'user' });155 assert.deepEqual(program.opts().optional, ['one', 'two']);156 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 157–158why, one step back157 });158Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 159–162why, one step back159 describe('variadic special cases', () => {160 test('when option flags has word character before dots then is variadic', () => {161 const program = new commander.Command();162 program.option('-c,--comma [value...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 163why, one step back163Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 164–165why, one step back164 assert.equal(program.options[0].variadic, true);165 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 166why, one step back166Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 167–170why, one step back167 test('when option flags has special characters before dots then not variadic', () => {168 // This might be used to describe coercion for comma separated values, and is not variadic.169 const program = new commander.Command();170 program.option('-c,--comma [value,...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 171why, one step back171Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 172–173why, one step back172 assert.equal(program.options[0].variadic, false);173 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 174why, one step back174 });Merge from develop (#2482)John Geebefore adoptionb51c0ea
lines 175–182why, one step back175176 test('when option has default array then specified value is used instead of default (not appended)', () => {177 const program = new commander.Command();178 program.option('-c,--comma [value...]', 'values', ['default']);179 program.parse(['--comma', 'CCC'], { from: 'user' });180181 assert.deepEqual(program.opts().comma, ['CCC']);182 });Merge from develop into release/15.x (with minor conflicts and test migrations)John Geebefore adoption26e3ba3
lines 183–190why, one step back183184 test('when option has default array then specified value is used instead of default (not appended)', () => {185 const program = new commander.Command();186 program.option('-c,--comma [value...]', 'values', ['default']);187 program.parse(['--comma', 'CCC'], { from: 'user' });188189 assert.deepEqual(program.opts().comma, ['CCC']);190 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 191why, one step back191});