options.optional.test.js
This file
Path
tests/options.optional.test.js
71 lines · 2.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–8why, one step back45// option with optional value, no default6describe('option with optional value, no default', () => {7 test('when option not specified then value is undefined', () => {8 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 9why, one step back9 program.option('--cheese [type]', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 10why, one step back10 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 11why, one step back11 assert.equal(program.opts().cheese, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 12–15why, one step back12 });1314 test('when option specified then value is as specified', () => {15 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 16why, one step back16 program.option('--cheese [type]', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 17–18why, one step back17 const cheeseType = 'blue';18 program.parse(['node', 'test', '--cheese', cheeseType]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 19why, one step back19 assert.equal(program.opts().cheese, cheeseType);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 20–23why, one step back20 });2122 test('when option specified without value then value is true', () => {23 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 24why, one step back24 program.option('--cheese [type]', 'cheese type');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 25why, one step back25 program.parse(['node', 'test', '--cheese']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 26why, one step back26 assert.equal(program.opts().cheese, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 27–31why, one step back27 });2829 test('when option specified without value and following option then value is true', () => {30 // optional options do not eat values with dashes31 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 32why, one step back32 program.option('--cheese [type]', 'cheese type').option('--some-option');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 33why, one step back33 program.parse(['node', 'test', '--cheese', '--some-option']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 34why, one step back34 assert.equal(program.opts().cheese, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 35–42why, one step back35 });36});3738// option with optional value, with default39describe('option with optional value, with default', () => {40 test('when option not specified then value is default', () => {41 const defaultValue = 'default';42 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 43why, one step back43 program.option('--cheese [type]', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 44why, one step back44 program.parse(['node', 'test']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 45why, one step back45 assert.equal(program.opts().cheese, defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 46–50why, one step back46 });4748 test('when option specified then value is as specified', () => {49 const defaultValue = 'default';50 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 51why, one step back51 program.option('--cheese [type]', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 52–53why, one step back52 const cheeseType = 'blue';53 program.parse(['node', 'test', '--cheese', cheeseType]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 54why, one step back54 assert.equal(program.opts().cheese, cheeseType);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 55–59why, one step back55 });5657 test('when option specified without value then value is true', () => {58 const defaultValue = 'default';59 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 60why, one step back60 program.option('--cheese [type]', 'cheese type', defaultValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 61why, one step back61 program.parse(['node', 'test', '--cheese']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 62why, one step back62 assert.equal(program.opts().cheese, true);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 63–66why, one step back63 });6465 test('when option specified without value and preset then value is preset', () => {66 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 67why, one step back67 program.addOption(new commander.Option('--cheese [type]').preset('preset'));Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 68why, one step back68 program.parse(['node', 'test', '--cheese']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 69why, one step back69 assert.equal(program.opts().cheese, 'preset');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 70–71why, one step back70 });71});