command.parse.test.js
This file
Path
tests/command.parse.test.js
442 lines · 16.0 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 cc2db5b point at it.
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 1–3why, one step back1import * as commander from '../index.js';2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
lines 4–8why, one step back45// Testing some Electron conventions but not directly using Electron to avoid overheads.6// https://github.com/electron/electron/issues/4690#issuecomment-2174352227// https://www.electronjs.org/docs/api/process#processdefaultapp-readonly8Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390
lines 9–11why, one step back9// (If mutating process.argv and process.execArgv causes problems, could add utility10// functions to get them and then mock the functions for tests.)11Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 12–22why, one step back12describe('Command.parse()', () => {13 describe('.parse() explicit (from:) and autodetection of args format parsing', () => {14 test('when no args then use process.argv and app/script/args', () => {15 const program = new commander.Command();16 program.argument('[args...]');17 const hold = process.argv;18 process.argv = 'node script.js user'.split(' ');19 program.parse();20 process.argv = hold;21 assert.deepEqual(program.args, ['user']);22 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 23why, one step back23Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 24–34why, one step back24 test('when no args and electron properties and not default app then use process.argv and app/args', () => {25 const program = new commander.Command();26 program.argument('[args...]');27 const holdArgv = process.argv;28 process.versions.electron = '1.2.3';29 process.argv = 'node user'.split(' ');30 program.parse();31 delete process.versions.electron;32 process.argv = holdArgv;33 assert.deepEqual(program.args, ['user']);34 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 35why, one step back35Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 36–41why, one step back36 test('when args then app/script/args', () => {37 const program = new commander.Command();38 program.argument('[args...]');39 program.parse('node script.js user'.split(' '));40 assert.deepEqual(program.args, ['user']);41 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 42why, one step back42Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 43–48why, one step back43 test('when args from "node" then app/script/args', () => {44 const program = new commander.Command();45 program.argument('[args...]');46 program.parse('node script.js user'.split(' '), { from: 'node' });47 assert.deepEqual(program.args, ['user']);48 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 49why, one step back49Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 50–58why, one step back50 test('when args from "electron" and not default app then app/args', () => {51 const program = new commander.Command();52 program.argument('[args...]');53 const hold = process.defaultApp;54 process.defaultApp = undefined;55 program.parse('customApp user'.split(' '), { from: 'electron' });56 process.defaultApp = hold;57 assert.deepEqual(program.args, ['user']);58 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 59why, one step back59Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 60–68why, one step back60 test('when args from "electron" and default app then app/script/args', () => {61 const program = new commander.Command();62 program.argument('[args...]');63 const hold = process.defaultApp;64 process.defaultApp = true;65 program.parse('electron script user'.split(' '), { from: 'electron' });66 process.defaultApp = hold;67 assert.deepEqual(program.args, ['user']);68 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 69why, one step back69Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 70–75why, one step back70 test('when args from "user" then args', () => {71 const program = new commander.Command();72 program.argument('[args...]');73 program.parse('user'.split(' '), { from: 'user' });74 assert.deepEqual(program.args, ['user']);75 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 76why, one step back76Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 77–82why, one step back77 test('when args from "silly" then throw', () => {78 const program = new commander.Command();79 program.argument('[args...]');80 assert.throws(() => {81 program.parse(['node', 'script.js'], { from: 'silly' });82 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 83why, one step back83 });Add auto-detection of args when node evaluating script code on command-line (#2164)John Geebefore adoptionb9ca390
line 84why, one step back84Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 85–99why, one step back85 describe('when node execArgv includes node flags', () => {86 ['-e', '--eval', '-p', '--print'].forEach((flag) => {87 test(`when node execArgv includes ${flag} then app/args`, () => {88 const program = new commander.Command();89 program.argument('[args...]');90 const holdExecArgv = process.execArgv;91 const holdArgv = process.argv;92 process.argv = ['node', 'user-arg'];93 process.execArgv = [flag, 'console.log("hello, world")'];94 program.parse();95 process.argv = holdArgv;96 process.execArgv = holdExecArgv;97 assert.deepEqual(program.args, ['user-arg']);98 process.execArgv = holdExecArgv;99 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 100–102why, one step back100 });101 });102 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 103why, one step back103Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 104–108why, one step back104 describe('return type', () => {105 test('when call .parse then returns program', () => {106 const program = new commander.Command();107 program.argument('[args...]');108 program.action(() => {});Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 109why, one step back109Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 110–112why, one step back110 const result = program.parse(['node', 'test']);111 assert.equal(result, program);112 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 113why, one step back113Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 114–117why, one step back114 test('when await .parseAsync then returns program', async () => {115 const program = new commander.Command();116 program.argument('[args...]');117 program.action(() => {});Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 118why, one step back118Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 119–121why, one step back119 const result = await program.parseAsync(['node', 'test']);120 assert.equal(result, program);121 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
lines 122–123why, one step back122 });123Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 124–125why, one step back124 // Easy mistake to make when writing unit tests125 test('when parse strings instead of array then throw', () => {Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 126why, one step back126 const program = new commander.Command();Disallow excess arguments (#2223)John Geebefore adoption58c28eb
line 127why, one step back127 program.argument('[args...]');Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 128–130why, one step back128 assert.throws(() => {129 program.parse('node', 'test');130 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
lines 131–132why, one step back131 });132Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 133–142why, one step back133 describe('parse parameter is treated as readonly, per TypeScript declaration', () => {134 test('when parse called then parameter does not change', () => {135 const program = new commander.Command();136 program.argument('[args...]');137 program.option('--debug');138 const original = ['node', '--debug', 'arg'];139 const param = original.slice();140 program.parse(param);141 assert.deepEqual(param, original);142 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 143why, one step back143Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 144–154why, one step back144 test('when parse called and parsed args later changed then parameter does not change', () => {145 const program = new commander.Command();146 program.argument('[args...]');147 program.option('--debug');148 const original = ['node', '--debug', 'arg'];149 const param = original.slice();150 program.parse(param);151 program.args.length = 0;152 program.rawArgs.length = 0;153 assert.deepEqual(param, original);154 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 155why, one step back155Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 156–167why, one step back156 test('when parse called and param later changed then parsed args do not change', () => {157 const program = new commander.Command();158 program.argument('[args...]');159 program.option('--debug');160 const param = ['node', '--debug', 'arg'];161 program.parse(param);162 const oldArgs = program.args.slice();163 const oldRawArgs = program.rawArgs.slice();164 param.length = 0;165 assert.deepEqual(program.args, oldArgs);166 assert.deepEqual(program.rawArgs, oldRawArgs);167 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
lines 168–169why, one step back168 });169Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 170–179why, one step back170 describe('parseAsync parameter is treated as readonly, per TypeScript declaration', () => {171 test('when parse called then parameter does not change', async () => {172 const program = new commander.Command();173 program.argument('[args...]');174 program.option('--debug');175 const original = ['node', '--debug', 'arg'];176 const param = original.slice();177 await program.parseAsync(param);178 assert.deepEqual(param, original);179 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 180why, one step back180Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 181–204why, one step back181 test('when parseAsync called and parsed args later changed then parameter does not change', async () => {182 const program = new commander.Command();183 program.argument('[args...]');184 program.option('--debug');185 const original = ['node', '--debug', 'arg'];186 const param = original.slice();187 await program.parseAsync(param);188 program.args.length = 0;189 program.rawArgs.length = 0;190 assert.deepEqual(param, original);191 });192193 test('when parseAsync called and param later changed then parsed args do not change', async () => {194 const program = new commander.Command();195 program.argument('[args...]');196 program.option('--debug');197 const param = ['node', '--debug', 'arg'];198 await program.parseAsync(param);199 const oldArgs = program.args.slice();200 const oldRawArgs = program.rawArgs.slice();201 param.length = 0;202 assert.deepEqual(program.args, oldArgs);203 assert.deepEqual(program.rawArgs, oldRawArgs);204 });Add optional summary for short form of subcommand description. (#1726)John Geebefore adoptioncc2db5b
line 205why, one step back205 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 206why, one step back206Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 207–211why, one step back207 describe('.parse() called multiple times', () => {208 test('when use boolean options then option values reset', () => {209 const program = new commander.Command()210 .option('--black')211 .option('--white');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 212why, one step back212Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 213–214why, one step back213 program.parse(['--black'], { from: 'user' });214 assert.deepEqual(program.opts(), { black: true });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 215why, one step back215Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 216–218why, one step back216 program.parse(['--white'], { from: 'user' });217 assert.deepEqual(program.opts(), { white: true });218 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 219why, one step back219Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 220–223why, one step back220 test('when use options with option-argument then option values and sources reset', () => {221 const program = new commander.Command()222 .option('-f, --foo <value>')223 .option('-b, --bar <value>');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 224why, one step back224Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 225–228why, one step back225 program.parse(['--foo', 'FOO'], { from: 'user' });226 assert.deepEqual(program.opts(), { foo: 'FOO' });227 assert.equal(program.getOptionValueSource('foo'), 'cli');228 assert.equal(program.getOptionValueSource('bar'), undefined);Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 229why, one step back229Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 230–234why, one step back230 program.parse(['--bar', 'BAR'], { from: 'user' });231 assert.deepEqual(program.opts(), { bar: 'BAR' });232 assert.equal(program.getOptionValueSource('foo'), undefined);233 assert.equal(program.getOptionValueSource('bar'), 'cli');234 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 235why, one step back235Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 236–239why, one step back236 test('when use options with option-argument and default then option values and sources reset', () => {237 const program = new commander.Command()238 .option('-f, --foo <value>', 'description', 'default-FOO')239 .option('-b, --bar <value>', 'description', 'default-BAR');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 240why, one step back240Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 241–244why, one step back241 program.parse(['--foo', 'FOO'], { from: 'user' });242 assert.deepEqual(program.opts(), { foo: 'FOO', bar: 'default-BAR' });243 assert.equal(program.getOptionValueSource('foo'), 'cli');244 assert.equal(program.getOptionValueSource('bar'), 'default');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 245why, one step back245Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 246–250why, one step back246 program.parse(['--bar', 'BAR'], { from: 'user' });247 assert.deepEqual(program.opts(), { foo: 'default-FOO', bar: 'BAR' });248 assert.equal(program.getOptionValueSource('foo'), 'default');249 assert.equal(program.getOptionValueSource('bar'), 'cli');250 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 251why, one step back251Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 252–255why, one step back252 test('when use negated options then option values reset', () => {253 const program = new commander.Command()254 .option('--no-foo')255 .option('--no-bar');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 256why, one step back256Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 257–258why, one step back257 program.parse(['--no-foo'], { from: 'user' });258 assert.deepEqual(program.opts(), { foo: false, bar: true });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 259why, one step back259Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 260–262why, one step back260 program.parse(['--no-bar'], { from: 'user' });261 assert.deepEqual(program.opts(), { foo: true, bar: false });262 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 263why, one step back263Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 264–265why, one step back264 test('when use variadic option then option values reset', () => {265 const program = new commander.Command().option('--var <items...>');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 266why, one step back266Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 267–268why, one step back267 program.parse(['--var', 'a', 'b'], { from: 'user' });268 assert.deepEqual(program.opts(), { var: ['a', 'b'] });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 269why, one step back269Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 270–272why, one step back270 program.parse(['--var', 'c'], { from: 'user' });271 assert.deepEqual(program.opts(), { var: ['c'] });272 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 273why, one step back273Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 274–279why, one step back274 test('when use collect example then option value resets', () => {275 function collect(value, previous) {276 return previous.concat([value]);277 }278 const program = new commander.Command();279 program.option('-c, --collect <value>', 'repeatable value', collect, []);Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 280why, one step back280Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 281–282why, one step back281 program.parse(['-c', 'a', '-c', 'b'], { from: 'user' });282 assert.deepEqual(program.opts(), { collect: ['a', 'b'] });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 283why, one step back283Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 284–286why, one step back284 program.parse(['-c', 'c'], { from: 'user' });285 assert.deepEqual(program.opts(), { collect: ['c'] });286 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 287why, one step back287Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 288–298why, one step back288 test('when use increaseVerbosity example then option value resets', () => {289 function increaseVerbosity(dummyValue, previous) {290 return previous + 1;291 }292 const program = new commander.Command();293 program.option(294 '-v, --verbose',295 'verbosity that can be increased',296 increaseVerbosity,297 0,298 );Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 299why, one step back299Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 300–302why, one step back300 program.parse(['-vvv'], { from: 'user' });301 assert.deepEqual(program.opts(), { verbose: 3 });302 program.parse(['-vv'], { from: 'user' });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 303why, one step back303Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 304–307why, one step back304 assert.deepEqual(program.opts(), { verbose: 2 });305 program.parse([], { from: 'user' });306 assert.deepEqual(program.opts(), { verbose: 0 });307 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 308why, one step back308Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 309–312why, one step back309 test('when use parse and parseAsync then option values reset', async () => {310 const program = new commander.Command()311 .option('--black')312 .option('--white');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 313why, one step back313Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 314–318why, one step back314 program.parse(['--black'], { from: 'user' });315 assert.deepEqual(program.opts(), { black: true });316 await program.parseAsync(['--white'], { from: 'user' });317 assert.deepEqual(program.opts(), { white: true });318 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 319why, one step back319Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 320–327why, one step back320 test('when call subcommand then option values reset (program and subcommand)', () => {321 const program = new commander.Command()322 .option('--black')323 .option('--white');324 const subcommand = program325 .command('sub')326 .option('--red')327 .option('--green');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 328why, one step back328Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 329–333why, one step back329 program.parse(['--black', 'sub', '--red'], { from: 'user' });330 assert.deepEqual(subcommand.optsWithGlobals(), {331 black: true,332 red: true,333 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 334why, one step back334Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 335–339why, one step back335 program.parse(['--white', 'sub', '--green'], { from: 'user' });336 assert.deepEqual(subcommand.optsWithGlobals(), {337 white: true,338 green: true,339 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 340why, one step back340 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 341why, one step back341Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 342–346why, one step back342 test('when call different subcommand then no reset because lazy', () => {343 // This is not a required behaviour, but is the intended behaviour.344 const program = new commander.Command();345 const sub1 = program.command('sub1').option('--red');346 const sub2 = program.command('sub2').option('--green');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 347why, one step back347Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 348–350why, one step back348 program.parse(['sub1', '--red'], { from: 'user' });349 assert.deepEqual(sub1.opts(), { red: true });350 assert.deepEqual(sub2.opts(), {});Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 351why, one step back351Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 352–355why, one step back352 program.parse(['sub2', '--green'], { from: 'user' });353 assert.deepEqual(sub1.opts(), { red: true });354 assert.deepEqual(sub2.opts(), { green: true });355 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 356why, one step back356Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 357–358why, one step back357 test('when parse with different implied program name then name changes', () => {358 const program = new commander.Command();Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 359why, one step back359Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 360–361why, one step back360 program.parse(['node', 'script1.js']);361 assert.equal(program.name(), 'script1');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 362why, one step back362Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 363–365why, one step back363 program.parse(['electron', 'script2.js']);364 assert.equal(program.name(), 'script2');365 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 366why, one step back366Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 367–371why, one step back367 test('when parse with different arguments then args change', () => {368 // weak test, would work without store/reset!369 const program = new commander.Command()370 .argument('<first>')371 .argument('[second]');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 372why, one step back372Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 373–374why, one step back373 program.parse(['one', 'two'], { from: 'user' });374 assert.deepEqual(program.args, ['one', 'two']);Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 375why, one step back375Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 376–378why, one step back376 program.parse(['alpha'], { from: 'user' });377 assert.deepEqual(program.args, ['alpha']);378 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 379why, one step back379Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 380–385why, one step back380 test('when parse with different arguments then rawArgs change', () => {381 // weak test, would work without store/reset!382 const program = new commander.Command()383 .argument('<first>')384 .option('--white')385 .option('--black');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 386why, one step back386Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 387–388why, one step back387 program.parse(['--white', 'one'], { from: 'user' });388 assert.deepEqual(program.rawArgs, ['--white', 'one']);Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 389why, one step back389Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 390–392why, one step back390 program.parse(['--black', 'two'], { from: 'user' });391 assert.deepEqual(program.rawArgs, ['--black', 'two']);392 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 393why, one step back393Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 394–400why, one step back394 test('when parse with different arguments then processedArgs change', () => {395 // weak test, would work without store/reset!396 const program = new commander.Command().argument(397 '<first>',398 'first arg',399 parseFloat,400 );Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 401why, one step back401Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 402–403why, one step back402 program.parse([123], { from: 'user' });403 assert.deepEqual(program.processedArgs, [123]);Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 404why, one step back404Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 405–407why, one step back405 program.parse([456], { from: 'user' });406 assert.deepEqual(program.processedArgs, [456]);407 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 408why, one step back408Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 409–421why, one step back409 test('when parse subcommand then reset state before preSubcommand hook called', () => {410 let hookCalled = false;411 const program = new commander.Command().hook(412 'preSubcommand',413 (thisCommand, subcommand) => {414 hookCalled = true;415 assert.deepEqual(subcommand.opts(), {});416 },417 );418 const subcommand = program419 .command('sub')420 .option('--red')421 .option('--green');Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 422why, one step back422Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 423–426why, one step back423 hookCalled = false;424 program.parse(['sub', '--red'], { from: 'user' });425 assert.equal(hookCalled, true);426 assert.deepEqual(subcommand.opts(), { red: true });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 427why, one step back427Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 428–432why, one step back428 hookCalled = false;429 program.parse(['sub', '--green'], { from: 'user' });430 assert.equal(hookCalled, true);431 assert.deepEqual(subcommand.opts(), { green: true });432 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 433why, one step back433Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 434–435why, one step back434 test('when using storeOptionsAsProperties then throw on second parse', () => {435 const program = new commander.Command().storeOptionsAsProperties();Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
line 436why, one step back436 program.parse();Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 437–439why, one step back437 assert.throws(() => {438 program.parse();439 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 440why, one step back440 });Add save/restore state to allow multiple calls to parse (#2299)John Geebefore adoption49423a2
lines 441–442why, one step back441 });442});