Skip to content
Myr

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 file

Take 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 back
1import * 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 back
5

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

lines 6–10why, one step back
6describe('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 back
11

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

lines 12–14why, one step back
12 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 back
15 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 16why, one step back
16

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

lines 17–19why, one step back
17 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 back
20

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

lines 21–23why, one step back
21 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 back
24

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

lines 25–27why, one step back
25 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 back
28

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

lines 29–31why, one step back
29 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 back
32

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

lines 33–35why, one step back
33 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 back
36

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

lines 37–41why, one step back
37 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 back
42

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

lines 43–50why, one step back
43 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 back
51

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

lines 52–54why, one step back
52 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 back
55

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

lines 56–63why, one step back
56 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 back
64

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

lines 65–67why, one step back
65 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 back
68

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

lines 69–71why, one step back
69 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 back
72

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

lines 73–75why, one step back
73 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 back
76

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

lines 77–79why, one step back
77 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 back
80

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

lines 81–83why, one step back
81 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 back
84

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

lines 85–90why, one step back
85 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 back
91

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

lines 92–96why, one step back
92 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 back
97

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

lines 98–104why, one step back
98 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 back
105

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

lines 106–108why, one step back
106 program.parse([], { from: 'user' });
107 assert.equal(program.opts().required, 'default');108 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 109why, one step back
109

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

lines 110–116why, one step back
110 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 back
117

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

lines 118–121why, one step back
118 // 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 back
122 });
123

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

lines 124–128why, one step back
124 // Not retesting everything, but do some tests on variadic with optional
125 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 back
129

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

lines 130–132why, one step back
130 program.parse([], { from: 'user' });
131 assert.equal(program.opts().optional, undefined);132 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 133why, one step back
133

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

lines 134–136why, one step back
134 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 back
137

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

lines 138–140why, one step back
138 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 back
141

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

lines 142–144why, one step back
142 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 back
145

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

lines 146–148why, one step back
146 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 back
149

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

lines 150–152why, one step back
150 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 back
153

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

lines 154–156why, one step back
154 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 back
157 });
158

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

lines 159–162why, one step back
159 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 back
163

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

lines 164–165why, one step back
164 assert.equal(program.options[0].variadic, true);
165 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 166why, one step back
166

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

lines 167–170why, one step back
167 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 back
171

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

lines 172–173why, one step back
172 assert.equal(program.options[0].variadic, false);
173 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 174why, one step back
174 });

Merge from develop (#2482)John Geebefore adoptionb51c0ea

lines 175–182why, one step back
175
176 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 back
183
184 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 back
191});