Skip to content
Myr

options.mandatory.test.js

This file

Path

tests/options.mandatory.test.js

223 lines · 7.8 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

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

lines 5–8why, one step back
5
6// Assuming mandatory options behave as normal options apart from the mandatory aspect, not retesting all behaviour.7// Likewise, not redoing all tests on subcommand after testing on program.8

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

lines 9–16why, one step back
9describe('Command.requiredOption()', () => {
10 describe('required program option with mandatory value specified', () => {11 test('when program has required value specified then value as specified', () => {12 const program = new commander.Command();13 program.requiredOption('--cheese <type>', 'cheese type');14 program.parse(['node', 'test', '--cheese', 'blue']);15 assert.equal(program.opts().cheese, 'blue');16 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 17why, one step back
17

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

lines 18–23why, one step back
18 test('when program has option with name different than property then still recognised', () => {
19 const program = new commander.Command();20 program.requiredOption('--cheese-type <type>', 'cheese type');21 program.parse(['node', 'test', '--cheese-type', 'blue']);22 assert.equal(program.opts().cheeseType, 'blue');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–30why, one step back
25 test('when program has required value default then default value', () => {
26 const program = new commander.Command();27 program.requiredOption('--cheese <type>', 'cheese type', 'default');28 program.parse(['node', 'test']);29 assert.equal(program.opts().cheese, 'default');30 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 31why, one step back
31

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

lines 32–37why, one step back
32 test('when program has optional value flag specified then true', () => {
33 const program = new commander.Command();34 program.requiredOption('--cheese [type]', 'cheese type');35 program.parse(['node', 'test', '--cheese']);36 assert.equal(program.opts().cheese, true);37 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 38why, one step back
38

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

lines 39–44why, one step back
39 test('when program has optional value default then default value', () => {
40 const program = new commander.Command();41 program.requiredOption('--cheese [type]', 'cheese type', 'default');42 program.parse(['node', 'test']);43 assert.equal(program.opts().cheese, 'default');44 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 45why, one step back
45

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

lines 46–53why, one step back
46 test('when program has value/no flag specified with value then specified value', () => {
47 const program = new commander.Command();48 program49 .requiredOption('--cheese <type>', 'cheese type')50 .requiredOption('--no-cheese', 'no cheese thanks');51 program.parse(['node', 'test', '--cheese', 'blue']);52 assert.equal(program.opts().cheese, 'blue');53 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 54why, one step back
54

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

lines 55–62why, one step back
55 test('when program has mandatory-yes/no flag specified with flag then true', () => {
56 const program = new commander.Command();57 program58 .requiredOption('--cheese', 'cheese type')59 .option('--no-cheese', 'no cheese thanks');60 program.parse(['node', 'test', '--cheese']);61 assert.equal(program.opts().cheese, true);62 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 63why, one step back
63

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

lines 64–71why, one step back
64 test('when program has mandatory-yes/mandatory-no flag specified with flag then true', () => {
65 const program = new commander.Command();66 program67 .requiredOption('--cheese', 'cheese type')68 .requiredOption('--no-cheese', 'no cheese thanks');69 program.parse(['node', 'test', '--cheese']);70 assert.equal(program.opts().cheese, true);71 });

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–80why, one step back
73 test('when program has yes/no flag specified negated then false', () => {
74 const program = new commander.Command();75 program76 .requiredOption('--cheese <type>', 'cheese type')77 .option('--no-cheese', 'no cheese thanks');78 program.parse(['node', 'test', '--no-cheese']);79 assert.equal(program.opts().cheese, false);80 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 81why, one step back
81

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

lines 82–90why, one step back
82 test('when program has required value specified and subcommand then specified value', () => {
83 const program = new commander.Command();84 program85 .requiredOption('--cheese <type>', 'cheese type')86 .command('sub')87 .action(() => {});88 program.parse(['node', 'test', '--cheese', 'blue', 'sub']);89 assert.equal(program.opts().cheese, 'blue');90 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 91–92why, one step back
91 });
92

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

lines 93–96why, one step back
93 describe('required program option with mandatory value not specified', () => {
94 test('when program has required option not specified then error', () => {95 const program = createTestCommand();96 program.requiredOption('--cheese <type>', 'cheese type');

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–100why, one step back
98 assert.throws(() => {
99 program.parse(['node', 'test']);100 });

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

line 101why, one step back
101 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 102why, one step back
102

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

lines 103–105why, one step back
103 test('when program has optional option not specified then error', () => {
104 const program = createTestCommand();105 program.requiredOption('--cheese [type]', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 106why, one step back
106

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

lines 107–109why, one step back
107 assert.throws(() => {
108 program.parse(['node', 'test']);109 });

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

line 110why, one step back
110 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 111why, one step back
111

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

lines 112–116why, one step back
112 test('when program has yes/no not specified then error', () => {
113 const program = createTestCommand();114 program115 .requiredOption('--cheese', 'cheese type')116 .option('--no-cheese', 'no cheese thanks');

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–120why, one step back
118 assert.throws(() => {
119 program.parse(['node', 'test']);120 });

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

line 121why, one step back
121 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 122why, one step back
122

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

lines 123–128why, one step back
123 test('when program has required value not specified and subcommand then error', () => {
124 const program = createTestCommand();125 program126 .requiredOption('--cheese <type>', 'cheese type')127 .command('sub')128 .action(() => {});

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 assert.throws(() => {
131 program.parse(['node', 'test', 'sub']);132 });

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

line 133why, one step back
133 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 134–135why, one step back
134 });
135

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

lines 136–145why, one step back
136 describe('required command option with mandatory value specified', () => {
137 test('when command has required value specified then no error and option has specified value', () => {138 const program = createTestCommand();139 let cmdOptions;140 program141 .command('sub')142 .requiredOption('--subby <type>', 'description')143 .action((options) => {144 cmdOptions = options;145 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 146why, one step back
146

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

line 147why, one step back
147 program.parse(['node', 'test', 'sub', '--subby', 'blue']);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 148why, one step back
148

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

lines 149–150why, one step back
149 assert.equal(cmdOptions.subby, 'blue');
150 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 151why, one step back
151

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

lines 152–158why, one step back
152 test('when command has required value specified using env then no error and option has specified value', () => {
153 const program = createTestCommand();154 program.addOption(155 new commander.Option('-p, --port <number>', 'port number')156 .makeOptionMandatory()157 .env('FOO'),158 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 159why, one step back
159

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

lines 160–162why, one step back
160 process.env.FOO = 'bar';
161 program.parse([], { from: 'user' });162 delete process.env.FOO;

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.opts().port, 'bar');
165 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 166–167why, one step back
166 });
167

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

lines 168–174why, one step back
168 describe('required command option with mandatory value not specified', () => {
169 test('when command has required value not specified then error', () => {170 const program = createTestCommand();171 program172 .command('sub')173 .requiredOption('--subby <type>', 'description')174 .action(() => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 175why, one step back
175

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

lines 176–178why, one step back
176 assert.throws(() => {
177 program.parse(['node', 'test', 'sub']);178 });

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

line 179why, one step back
179 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 180why, one step back
180

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

lines 181–187why, one step back
181 test('when command has required value but not called then no error', () => {
182 const program = createTestCommand();183 program184 .command('sub')185 .requiredOption('--subby <type>', 'description')186 .action(() => {});187 program.command('sub2');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 188why, one step back
188

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

lines 189–191why, one step back
189 assert.doesNotThrow(() => {
190 program.parse(['node', 'test', 'sub2']);191 });

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

line 192why, one step back
192 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 193–194why, one step back
193 });
194

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

lines 195–198why, one step back
195 describe('missing mandatory option but help requested', () => {
196 test('when program has required option not specified and --help then help', () => {197 const program = createTestCommand();198 program.requiredOption('--cheese <type>', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 199why, one step back
199

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

lines 200–206why, one step back
200 assert.throws(
201 () => {202 program.parse(['node', 'test', '--help']);203 },204 { code: 'commander.helpDisplayed' },205 );206 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 207why, one step back
207

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

lines 208–213why, one step back
208 test('when program has required option not specified and subcommand --help then help', () => {
209 const program = createTestCommand();210 program211 .requiredOption('--cheese <type>', 'cheese type')212 .command('sub')213 .action(() => {});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 214why, one step back
214

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

lines 215–221why, one step back
215 assert.throws(
216 () => {217 program.parse(['node', 'test', 'sub', '--help']);218 },219 { code: 'commander.helpDisplayed' },220 );221 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 222–223why, one step back
222 });
223});