Skip to content
Myr

options.optional.test.js

This file

Path

tests/options.optional.test.js

78 lines · 2.8 KiB · JavaScript

Last changed by

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

History of this file

Take it

The walk stopped after 200 commits: lines older than f47bdf5 point at it.

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 1–9why, one step back
1const commander = require('../');
23// option with optional value, no default4describe('option with optional value, no default', () => {5 test('when option not specified then value is undefined', () => {6 const program = new commander.Command();7 program8 .option('--cheese [type]', 'cheese type');9 program.parse(['node', 'test']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 10why, one step back
10 expect(program.opts().cheese).toBeUndefined();

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 11–18why, one step back
11 });
1213 test('when option specified then value is as specified', () => {14 const program = new commander.Command();15 program16 .option('--cheese [type]', 'cheese type');17 const cheeseType = 'blue';18 program.parse(['node', 'test', '--cheese', cheeseType]);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 19why, one step back
19 expect(program.opts().cheese).toBe(cheeseType);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 20–26why, one step back
20 });
2122 test('when option specified without value then value is true', () => {23 const program = new commander.Command();24 program25 .option('--cheese [type]', 'cheese type');26 program.parse(['node', 'test', '--cheese']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 27why, one step back
27 expect(program.opts().cheese).toBe(true);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 28–36why, one step back
28 });
2930 test('when option specified without value and following option then value is true', () => {31 // optional options do not eat values with dashes32 const program = new commander.Command();33 program34 .option('--cheese [type]', 'cheese type')35 .option('--some-option');36 program.parse(['node', 'test', '--cheese', '--some-option']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 37why, one step back
37 expect(program.opts().cheese).toBe(true);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 38–48why, one step back
38 });
39});4041// option with optional value, with default42describe('option with optional value, with default', () => {43 test('when option not specified then value is default', () => {44 const defaultValue = 'default';45 const program = new commander.Command();46 program47 .option('--cheese [type]', 'cheese type', defaultValue);48 program.parse(['node', 'test']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 49why, one step back
49 expect(program.opts().cheese).toBe(defaultValue);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 50–58why, one step back
50 });
5152 test('when option specified then value is as specified', () => {53 const defaultValue = 'default';54 const program = new commander.Command();55 program56 .option('--cheese [type]', 'cheese type', defaultValue);57 const cheeseType = 'blue';58 program.parse(['node', 'test', '--cheese', cheeseType]);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 59why, one step back
59 expect(program.opts().cheese).toBe(cheeseType);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 60–61why, one step back
60 });
61

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

line 62why, one step back
62 test('when option specified without value then value is true', () => {

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 63–67why, one step back
63 const defaultValue = 'default';
64 const program = new commander.Command();65 program66 .option('--cheese [type]', 'cheese type', defaultValue);67 program.parse(['node', 'test', '--cheese']);

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

lines 68–76why, one step back
68 expect(program.opts().cheese).toBe(true);
69 });7071 test('when option specified without value and preset then value is preset', () => {72 const program = new commander.Command();73 program74 .addOption(new commander.Option('--cheese [type]').preset('preset'));75 program.parse(['node', 'test', '--cheese']);76 expect(program.opts().cheese).toBe('preset');

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 77–78why, one step back
77 });
78});