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 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
lines 5–8why, one step back56// 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.8Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 9–16why, one step back9describe('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 back17Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 18–23why, one step back18 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 back24Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 25–30why, one step back25 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 back31Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 32–37why, one step back32 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 back38Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 39–44why, one step back39 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 back45Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 46–53why, one step back46 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 back54Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 55–62why, one step back55 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 back63Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 64–71why, one step back64 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 back72Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 73–80why, one step back73 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 back81Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 82–90why, one step back82 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 back91 });92Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 93–96why, one step back93 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 back97Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 98–100why, one step back98 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 back101 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 102why, one step back102Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 103–105why, one step back103 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 back106Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 107–109why, one step back107 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 back110 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 111why, one step back111Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 112–116why, one step back112 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 back117Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 118–120why, one step back118 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 back121 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 122why, one step back122Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 123–128why, one step back123 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 back129Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 130–132why, one step back130 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 back133 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 134–135why, one step back134 });135Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 136–145why, one step back136 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 back146Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 147why, one step back147 program.parse(['node', 'test', 'sub', '--subby', 'blue']);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 148why, one step back148Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 149–150why, one step back149 assert.equal(cmdOptions.subby, 'blue');150 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 151why, one step back151Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 152–158why, one step back152 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 back159Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 160–162why, one step back160 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 back163Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 164–165why, one step back164 assert.equal(program.opts().port, 'bar');165 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 166–167why, one step back166 });167Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 168–174why, one step back168 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 back175Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 176–178why, one step back176 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 back179 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 180why, one step back180Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 181–187why, one step back181 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 back188Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 189–191why, one step back189 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 back192 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 193–194why, one step back193 });194Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 195–198why, one step back195 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 back199Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 200–206why, one step back200 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 back207Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 208–213why, one step back208 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 back214Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 215–221why, one step back215 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 back222 });223});