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 fileTake 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 back1import * 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 back45// Test simple flag and negatable flag6Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 7–9why, one step back7// boolean option on program8describe('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 back10 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 11why, one step back11 program.option('--pepper', 'add pepper');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 12why, one step back12 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 13why, one step back13 assert.equal(program.opts().pepper, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 14–15why, one step back14 });15Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 16why, one step back16 test('when boolean option specified then value is true', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 17why, one step back17 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 18why, one step back18 program.option('--pepper', 'add pepper');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 19why, one step back19 program.parse(['node', 'test', '--pepper']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 20why, one step back20 assert.equal(program.opts().pepper, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 21–22why, one step back21 });22Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 23why, one step back23 test('when negatable boolean option not specified then value is true', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 24why, one step back24 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 25why, one step back25 program.option('--no-cheese', 'remove cheese');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 26why, one step back26 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 27why, one step back27 assert.equal(program.opts().cheese, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 28–29why, one step back28 });29Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 30why, one step back30 test('when negatable boolean option specified then value is false', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 31why, one step back31 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 32why, one step back32 program.option('--no-cheese', 'remove cheese');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 33why, one step back33 program.parse(['node', 'test', '--no-cheese']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 34why, one step back34 assert.equal(program.opts().cheese, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 35–37why, one step back35 });36});37Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 38–39why, one step back38describe('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 back40 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 back45 .action((options) => {46 subCommandOptions = options;47 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 48why, one step back48 program.parse(['node', 'test', 'sub']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 49why, one step back49 assert.equal(subCommandOptions.pepper, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 50–51why, one step back50 });51Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 52why, one step back52 test('when boolean option specified then value is true', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 53–57why, one step back53 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 back58 .action((options) => {59 subCommandOptions = options;60 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 61why, one step back61 program.parse(['node', 'test', 'sub', '--pepper']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 62why, one step back62 assert.equal(subCommandOptions.pepper, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 63–64why, one step back63 });64Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 65why, one step back65 test('when negatable boolean option not specified then value is true', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 66–70why, one step back66 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 back71 .action((options) => {72 subCommandOptions = options;73 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 74why, one step back74 program.parse(['node', 'test', 'sub']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 75why, one step back75 assert.equal(subCommandOptions.cheese, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 76–77why, one step back76 });77Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 78why, one step back78 test('when negatable boolean option specified then value is false', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 79–83why, one step back79 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 back84 .action((options) => {85 subCommandOptions = options;86 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 87why, one step back87 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 back88 assert.equal(subCommandOptions.cheese, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 89–94why, one step back89 });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 back95describe('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 back97 const flagValue = 'black';98 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 99why, one step back99 program.option('--olives', 'Add green olives?', flagValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 100why, one step back100 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 101why, one step back101 assert.equal(program.opts().olives, flagValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 102–103why, one step back102 });103Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 104why, one step back104 test('when option specified then value is true', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 105–106why, one step back105 const flagValue = 'black';106 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 107why, one step back107 program.option('-v, --olives', 'Add green olives?', flagValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 108why, one step back108 program.parse(['node', 'test', '--olives']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 109why, one step back109 assert.equal(program.opts().olives, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 110–111why, one step back110 });111Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 112why, one step back112 test('when combo option and negated then value is false', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 113–118why, one step back113 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 back119 assert.equal(program.opts().olives, false);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 120–123why, one step back120 });121});122123// Regression test for #1301 with `-no-` in middle of optionAdd describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 124–125why, one step back124describe('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 back126 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 127why, one step back127 program.option('--module-no-parse');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 128why, one step back128 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 129why, one step back129 assert.equal(program.opts().moduleNoParse, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 130–133why, one step back130 });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 back134 program.option('--module-no-parse');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 135why, one step back135 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 back136 assert.equal(program.opts().moduleNoParse, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 137–138why, one step back137 });138});