Skip to content
Myr

options.bool.combo.test.js

This file

Path

tests/options.bool.combo.test.js

195 lines · 7.2 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

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

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 1–3why, one step back
1import * as commander from '../index.js';
2import { test, describe } from 'node:test';3import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 4–7why, one step back
4
5// Test combination of flag and --no-flag6// (single flags tested in options.bool.test.js)7

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 8–17why, one step back
8describe('boolean option combos (--foo and --no-foo)', () => {
9 // boolean option combo with no default10 describe('positive option with no default', () => {11 function createPepperProgram() {12 const program = new commander.Command();13 program14 .option('-p, --pepper', 'add pepper')15 .option('-P, --no-pepper', 'remove pepper');16 return program;17 }

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 18why, one step back
18

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 19–23why, one step back
19 test('when option not specified then value is undefined', () => {
20 const program = createPepperProgram();21 program.parse(['node', 'test']);22 assert.equal(program.opts().pepper, undefined);23 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 24why, one step back
24

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 25–29why, one step back
25 test('when positive option then value is true', () => {
26 const program = createPepperProgram();27 program.parse(['node', 'test', '--pepper']);28 assert.equal(program.opts().pepper, true);29 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 30why, one step back
30

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 31–35why, one step back
31 test('when negative option then value is false', () => {
32 const program = createPepperProgram();33 program.parse(['node', 'test', '--no-pepper']);34 assert.equal(program.opts().pepper, false);35 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 36why, one step back
36

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 37–41why, one step back
37 test('when last option is positive then value is true', () => {
38 const program = createPepperProgram();39 program.parse(['node', 'test', '--no-pepper', '--pepper']);40 assert.equal(program.opts().pepper, true);41 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 42why, one step back
42

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 43–47why, one step back
43 test('when last option is negative then value is false', () => {
44 const program = createPepperProgram();45 program.parse(['node', 'test', '--pepper', '--no-pepper']);46 assert.equal(program.opts().pepper, false);47 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 48–49why, one step back
48 });
49

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

line 50why, one step back
50 // Flag with default, say from an environment variable.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 51why, one step back
51

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 52–58why, one step back
52 function createPepperProgramWithDefault(defaultValue) {
53 const program = new commander.Command();54 program55 .option('-p, --pepper', 'add pepper', defaultValue)56 .option('-P, --no-pepper', 'remove pepper');57 return program;58 }

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 59why, one step back
59

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 60–66why, one step back
60 // boolean option combo, default true, long flags
61 describe('option with default of true, long flags', () => {62 test('when option not specified then value is true', () => {63 const program = createPepperProgramWithDefault(true);64 program.parse(['node', 'test']);65 assert.equal(program.opts().pepper, true);66 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 67why, one step back
67

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 68–72why, one step back
68 test('when positive option then value is true', () => {
69 const program = createPepperProgramWithDefault(true);70 program.parse(['node', 'test', '--pepper']);71 assert.equal(program.opts().pepper, true);72 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 73why, one step back
73

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 74–78why, one step back
74 test('when negative option then value is false', () => {
75 const program = createPepperProgramWithDefault(true);76 program.parse(['node', 'test', '--no-pepper']);77 assert.equal(program.opts().pepper, false);78 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 79–80why, one step back
79 });
80

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 81–87why, one step back
81 // boolean option combo, default false, short flags
82 describe('option with default of false, short flags', () => {83 test('when option not specified then value is false', () => {84 const program = createPepperProgramWithDefault(false);85 program.parse(['node', 'test']);86 assert.equal(program.opts().pepper, false);87 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 88why, one step back
88

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 89–93why, one step back
89 test('when positive option then value is true', () => {
90 const program = createPepperProgramWithDefault(false);91 program.parse(['node', 'test', '-p']);92 assert.equal(program.opts().pepper, true);93 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 94why, one step back
94

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 95–99why, one step back
95 test('when negative option then value is false', () => {
96 const program = createPepperProgramWithDefault(false);97 program.parse(['node', 'test', '-P']);98 assert.equal(program.opts().pepper, false);99 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 100–101why, one step back
100 });
101

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 102–109why, one step back
102 // boolean option combo with non-boolean default.
103 // Changed behaviour to normal default in Commander 9.104 describe('option with non-boolean default', () => {105 test('when option not specified then value is default', () => {106 const program = createPepperProgramWithDefault('default');107 program.parse(['node', 'test']);108 assert.equal(program.opts().pepper, 'default');109 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 110why, one step back
110

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 111–115why, one step back
111 test('when positive option then value is true', () => {
112 const program = createPepperProgramWithDefault('default');113 program.parse(['node', 'test', '--pepper']);114 assert.equal(program.opts().pepper, true);115 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 116why, one step back
116

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 117–121why, one step back
117 test('when negative option then value is false', () => {
118 const program = createPepperProgramWithDefault('default');119 program.parse(['node', 'test', '--no-pepper']);120 assert.equal(program.opts().pepper, false);121 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 122–123why, one step back
122 });
123

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 124–135why, one step back
124 describe('option with non-boolean default and preset', () => {
125 function createPepperProgramWithDefaultAndPreset() {126 const program = new commander.Command();127 program128 .addOption(129 new commander.Option('-p, --pepper')130 .default('default')131 .preset('preset'),132 )133 .option('-P, --no-pepper', 'remove pepper');134 return program;135 }

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 136why, one step back
136

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 137–141why, one step back
137 test('when option not specified then value is default', () => {
138 const program = createPepperProgramWithDefaultAndPreset();139 program.parse(['node', 'test']);140 assert.equal(program.opts().pepper, 'default');141 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 142why, one step back
142

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 143–147why, one step back
143 test('when positive option then value is preset', () => {
144 const program = createPepperProgramWithDefaultAndPreset();145 program.parse(['node', 'test', '--pepper']);146 assert.equal(program.opts().pepper, 'preset');147 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 148why, one step back
148

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 149–153why, one step back
149 test('when negative option then value is false', () => {
150 const program = createPepperProgramWithDefaultAndPreset();151 program.parse(['node', 'test', '--no-pepper']);152 assert.equal(program.opts().pepper, false);153 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 154why, one step back
154 });

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

line 155why, one step back
155

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 156–162why, one step back
156 describe('only lone negative causes implicit default of true', () => {
157 test('when lone negative then default value is true', () => {158 const program = new commander.Command();159 program.option('--no-pepper', 'remove pepper');160 program.parse([], { from: 'user' });161 assert.equal(program.opts().pepper, true);162 });

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

line 163why, one step back
163

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 164–172why, one step back
164 test('when boolean combo and negative first then no implicit default', () => {
165 // New behaviour in Commander 15, now only lone negative gets implicit default of true.166 const program = new commander.Command();167 program168 .option('--no-pepper', 'remove pepper')169 .option('--pepper', 'pepper only');170 program.parse([], { from: 'user' });171 assert.equal(program.opts().pepper, undefined);172 });

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

line 173why, one step back
173

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 174–181why, one step back
174 test('when boolean combo and negative second then no implicit default', () => {
175 const program = new commander.Command();176 program177 .option('--pepper', 'pepper only')178 .option('--no-pepper', 'remove pepper');179 program.parse([], { from: 'user' });180 assert.equal(program.opts().pepper, undefined);181 });

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

line 182why, one step back
182

Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795

lines 183–193why, one step back
183 test('when boolean combo and negative second with explicit default then get explicit default', () => {
184 // Prior to Commander 15, negative second would ignore implicit and explicit default value.185 // Simpler rule now and the special default behaviour is for lone negative only. Add test since186 // intentional change of behaviour for unlikely edge case.187 const program = new commander.Command();188 program189 .option('--pepper', 'pepper only')190 .option('--no-pepper', 'remove pepper', 'plain');191 program.parse([], { from: 'user' });192 assert.equal(program.opts().pepper, 'plain');193 });

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

lines 194–195why, one step back
194 });
195});