Skip to content
Myr

options.bool.test.js

This file

Path

tests/options.bool.test.js

137 lines · 4.7 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–11why, one step back
1const commander = require('../');
23// Test simple flag and negatable flag45// boolean flag on program6describe('boolean flag on program', () => {7 test('when boolean flag not specified then value is undefined', () => {8 const program = new commander.Command();9 program10 .option('--pepper', 'add pepper');11 program.parse(['node', 'test']);

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

line 12why, one step back
12 expect(program.opts().pepper).toBeUndefined();

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

lines 13–19why, one step back
13 });
1415 test('when boolean flag specified then value is true', () => {16 const program = new commander.Command();17 program18 .option('--pepper', 'add pepper');19 program.parse(['node', 'test', '--pepper']);

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

line 20why, one step back
20 expect(program.opts().pepper).toBe(true);

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

lines 21–27why, one step back
21 });
2223 test('when negatable boolean flag not specified then value is true', () => {24 const program = new commander.Command();25 program26 .option('--no-cheese', 'remove cheese');27 program.parse(['node', 'test']);

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

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

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

lines 29–35why, one step back
29 });
3031 test('when negatable boolean flag specified then value is false', () => {32 const program = new commander.Command();33 program34 .option('--no-cheese', 'remove cheese');35 program.parse(['node', 'test', '--no-cheese']);

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

line 36why, one step back
36 expect(program.opts().cheese).toBe(false);

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

lines 37–42why, one step back
37 });
38});3940// boolean flag on command41describe('boolean flag on command', () => {42 test('when boolean flag not specified then value is undefined', () => {

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

line 43why, one step back
43 let subCommandOptions;

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

lines 44–47why, one step back
44 const program = new commander.Command();
45 program46 .command('sub')47 .option('--pepper', 'add pepper')

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

line 48why, one step back
48 .action((options) => { subCommandOptions = options; });

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

line 49why, one step back
49 program.parse(['node', 'test', 'sub']);

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

line 50why, one step back
50 expect(subCommandOptions.pepper).toBeUndefined();

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

lines 51–53why, one step back
51 });
5253 test('when boolean flag specified then value is true', () => {

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

line 54why, one step back
54 let subCommandOptions;

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

lines 55–58why, one step back
55 const program = new commander.Command();
56 program57 .command('sub')58 .option('--pepper', 'add pepper')

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

line 59why, one step back
59 .action((options) => { subCommandOptions = options; });

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

line 60why, one step back
60 program.parse(['node', 'test', 'sub', '--pepper']);

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

line 61why, one step back
61 expect(subCommandOptions.pepper).toBe(true);

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

lines 62–64why, one step back
62 });
6364 test('when negatable boolean flag not specified then value is true', () => {

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

line 65why, one step back
65 let subCommandOptions;

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

lines 66–69why, one step back
66 const program = new commander.Command();
67 program68 .command('sub')69 .option('--no-cheese', 'remove cheese')

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

line 70why, one step back
70 .action((options) => { subCommandOptions = options; });

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

line 71why, one step back
71 program.parse(['node', 'test', 'sub']);

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

line 72why, one step back
72 expect(subCommandOptions.cheese).toBe(true);

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

lines 73–75why, one step back
73 });
7475 test('when negatable boolean flag specified then value is false', () => {

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

line 76why, one step back
76 let subCommandOptions;

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

lines 77–80why, one step back
77 const program = new commander.Command();
78 program79 .command('sub')80 .option('--no-cheese', 'remove cheese')

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

line 81why, one step back
81 .action((options) => { subCommandOptions = options; });

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

line 82why, one step back
82 program.parse(['node', 'test', 'sub', '--no-cheese']);

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

line 83why, one step back
83 expect(subCommandOptions.cheese).toBe(false);

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

lines 84–87why, one step back
84 });
85});8687// boolean flag with non-boolean default

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

lines 88–89why, one step back
88// NB: behaviour changed in Commander v9 to have default be default.
89// These tests no longer match likely uses, but retained and updated to match current behaviour.

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

line 90why, one step back
90describe('boolean flag with non-boolean default', () => {

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

line 91why, one step back
91 test('when flag not specified then value is "default"', () => {

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

lines 92–94why, one step back
92 const flagValue = 'black';
93 const program = new commander.Command();94 program

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

line 95why, one step back
95 .option('--olives', 'Add green olives?', flagValue);

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

line 96why, one step back
96 program.parse(['node', 'test']);

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

line 97why, one step back
97 expect(program.opts().olives).toBe(flagValue);

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

lines 98–99why, one step back
98 });
99

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

line 100why, one step back
100 test('when flag specified then value is true', () => {

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

lines 101–103why, one step back
101 const flagValue = 'black';
102 const program = new commander.Command();103 program

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

line 104why, one step back
104 .option('-v, --olives', 'Add green olives?', flagValue);

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

line 105why, one step back
105 program.parse(['node', 'test', '--olives']);

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

line 106why, one step back
106 expect(program.opts().olives).toBe(true);

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

line 107why, one step back
107 });

Test coverage (#1433)John Geebefore adoption891e23d

line 108why, one step back
108

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

line 109why, one step back
109 test('when combo flag and negated then value is false', () => {

Test coverage (#1433)John Geebefore adoption891e23d

lines 110–112why, one step back
110 const flagValue = 'black';
111 const program = new commander.Command();112 program

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

line 113why, one step back
113 .option('-v, --olives', 'Add green olives?', flagValue)

Test coverage (#1433)John Geebefore adoption891e23d

lines 114–117why, one step back
114 .option('--no-olives');
115 program.parse(['node', 'test', '--olives', '--no-olives']);116 expect(program.opts().olives).toBe(false);117 });

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

lines 118–126why, one step back
118});
119120// Regression test for #1301 with `-no-` in middle of option121describe('regression test for -no- in middle of option flag', () => {122 test('when flag not specified then value is undefined', () => {123 const program = new commander.Command();124 program125 .option('--module-no-parse');126 program.parse(['node', 'test']);

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

line 127why, one step back
127 expect(program.opts().moduleNoParse).toBeUndefined();

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

lines 128–134why, one step back
128 });
129130 test('when flag specified then value is true', () => {131 const program = new commander.Command();132 program133 .option('--module-no-parse');134 program.parse(['node', 'test', '--module-no-parse']);

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

line 135why, one step back
135 expect(program.opts().moduleNoParse).toEqual(true);

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

lines 136–137why, one step back
136 });
137});