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 fileTake 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 back1const 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 back12 expect(program.opts().pepper).toBeUndefined();Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 13–19why, one step back13 });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 back20 expect(program.opts().pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 21–27why, one step back21 });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 back28 expect(program.opts().cheese).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 29–35why, one step back29 });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 back36 expect(program.opts().cheese).toBe(false);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 37–42why, one step back37 });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 back43 let subCommandOptions;Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 44–47why, one step back44 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 back48 .action((options) => { subCommandOptions = options; });Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 49why, one step back49 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 back50 expect(subCommandOptions.pepper).toBeUndefined();Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 51–53why, one step back51 });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 back54 let subCommandOptions;Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 55–58why, one step back55 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 back59 .action((options) => { subCommandOptions = options; });Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 60why, one step back60 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 back61 expect(subCommandOptions.pepper).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 62–64why, one step back62 });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 back65 let subCommandOptions;Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 66–69why, one step back66 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 back70 .action((options) => { subCommandOptions = options; });Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 71why, one step back71 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 back72 expect(subCommandOptions.cheese).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 73–75why, one step back73 });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 back76 let subCommandOptions;Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 77–80why, one step back77 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 back81 .action((options) => { subCommandOptions = options; });Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 82why, one step back82 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 back83 expect(subCommandOptions.cheese).toBe(false);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 84–87why, one step back84 });85});8687// boolean flag with non-boolean defaultMerge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 88–89why, one step back88// 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 back90describe('boolean flag with non-boolean default', () => {Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 91why, one step back91 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 back92 const flagValue = 'black';93 const program = new commander.Command();94 programMerge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 95why, one step back95 .option('--olives', 'Add green olives?', flagValue);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 96why, one step back96 program.parse(['node', 'test']);Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 97why, one step back97 expect(program.opts().olives).toBe(flagValue);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 98–99why, one step back98 });99Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 100why, one step back100 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 back101 const flagValue = 'black';102 const program = new commander.Command();103 programMerge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 104why, one step back104 .option('-v, --olives', 'Add green olives?', flagValue);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 105why, one step back105 program.parse(['node', 'test', '--olives']);Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 106why, one step back106 expect(program.opts().olives).toBe(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
line 107why, one step back107 });Test coverage (#1433)John Geebefore adoption891e23d
line 108why, one step back108Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 109why, one step back109 test('when combo flag and negated then value is false', () => {Test coverage (#1433)John Geebefore adoption891e23d
lines 110–112why, one step back110 const flagValue = 'black';111 const program = new commander.Command();112 programMerge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
line 113why, one step back113 .option('-v, --olives', 'Add green olives?', flagValue)Test coverage (#1433)John Geebefore adoption891e23d
lines 114–117why, one step back114 .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 back118});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 back127 expect(program.opts().moduleNoParse).toBeUndefined();Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 128–134why, one step back128 });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 back135 expect(program.opts().moduleNoParse).toEqual(true);Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5
lines 136–137why, one step back136 });137});