Skip to content
Myr

options.bool.test.js

This file

Path

tests/options.bool.test.js

138 lines · 4.8 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–6why, one step back
4
5// Test simple flag and negatable flag6

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

lines 7–9why, one step back
7// boolean option on program
8describe('boolean option on program', () => {9 test('when boolean option not specified then value is undefined', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 10why, one step back
10 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 11why, one step back
11 program.option('--pepper', 'add pepper');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 13why, one step back
13 assert.equal(program.opts().pepper, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 14–15why, one step back
14 });
15

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 17why, one step back
17 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 18why, one step back
18 program.option('--pepper', 'add pepper');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 20why, one step back
20 assert.equal(program.opts().pepper, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 21–22why, one step back
21 });
22

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

line 23why, one step back
23 test('when negatable boolean option not specified then value is true', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 24why, one step back
24 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 25why, one step back
25 program.option('--no-cheese', 'remove cheese');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 27why, one step back
27 assert.equal(program.opts().cheese, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 28–29why, one step back
28 });
29

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

line 30why, one step back
30 test('when negatable boolean option specified then value is false', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 31why, one step back
31 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 32why, one step back
32 program.option('--no-cheese', 'remove cheese');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 34why, one step back
34 assert.equal(program.opts().cheese, false);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 35–37why, one step back
35 });
36});37

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

lines 38–39why, one step back
38describe('boolean option on subcommand', () => {
39 test('when boolean option not specified then value is undefined', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 40–44why, one step back
40 let subCommandOptions;
41 const program = new commander.Command();42 program43 .command('sub')44 .option('--pepper', 'add pepper')

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 45–47why, one step back
45 .action((options) => {
46 subCommandOptions = options;47 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 49why, one step back
49 assert.equal(subCommandOptions.pepper, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 50–51why, one step back
50 });
51

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 53–57why, one step back
53 let subCommandOptions;
54 const program = new commander.Command();55 program56 .command('sub')57 .option('--pepper', 'add pepper')

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 58–60why, one step back
58 .action((options) => {
59 subCommandOptions = options;60 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 62why, one step back
62 assert.equal(subCommandOptions.pepper, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 63–64why, one step back
63 });
64

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

line 65why, one step back
65 test('when negatable boolean option not specified then value is true', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 66–70why, one step back
66 let subCommandOptions;
67 const program = new commander.Command();68 program69 .command('sub')70 .option('--no-cheese', 'remove cheese')

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 71–73why, one step back
71 .action((options) => {
72 subCommandOptions = options;73 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 75why, one step back
75 assert.equal(subCommandOptions.cheese, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

line 78why, one step back
78 test('when negatable boolean option specified then value is false', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 79–83why, one step back
79 let subCommandOptions;
80 const program = new commander.Command();81 program82 .command('sub')83 .option('--no-cheese', 'remove cheese')

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 84–86why, one step back
84 .action((options) => {
85 subCommandOptions = options;86 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 88why, one step back
88 assert.equal(subCommandOptions.cheese, false);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 89–94why, one step back
89 });
90});9192// boolean flag with non-boolean default93// NB: behaviour changed in Commander v9 to have default be default.94// These tests no longer match likely uses, but retained and updated to match current behaviour.

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

lines 95–96why, one step back
95describe('boolean option with non-boolean default', () => {
96 test('when option not specified then value is "default"', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 101why, one step back
101 assert.equal(program.opts().olives, flagValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 102–103why, one step back
102 });
103

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 109why, one step back
109 assert.equal(program.opts().olives, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 110–111why, one step back
110 });
111

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 113–118why, one step back
113 const flagValue = 'black';
114 const program = new commander.Command();115 program116 .option('-v, --olives', 'Add green olives?', flagValue)117 .option('--no-olives');118 program.parse(['node', 'test', '--olives', '--no-olives']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 119why, one step back
119 assert.equal(program.opts().olives, false);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 120–123why, one step back
120 });
121});122123// Regression test for #1301 with `-no-` in middle of option

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

lines 124–125why, one step back
124describe('regression test for -no- in middle of option name', () => {
125 test('when option not specified then value is undefined', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 126why, one step back
126 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 127why, one step back
127 program.option('--module-no-parse');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 129why, one step back
129 assert.equal(program.opts().moduleNoParse, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 130–133why, one step back
130 });
131132 test('when flag specified then value is true', () => {133 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 134why, one step back
134 program.option('--module-no-parse');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 135why, one step back
135 program.parse(['node', 'test', '--module-no-parse']);

Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086

line 136why, one step back
136 assert.equal(program.opts().moduleNoParse, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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