Skip to content
Myr

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 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–8why, one step back
4
5// 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 back
9 program.option('--cheese [type]', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

line 11why, one step back
11 assert.equal(program.opts().cheese, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 12–15why, one step back
12 });
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 back
16 program.option('--cheese [type]', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 17–18why, one step back
17 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 back
19 assert.equal(program.opts().cheese, cheeseType);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 20–23why, one step back
20 });
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 back
24 program.option('--cheese [type]', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 27–31why, one step back
27 });
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 back
32 program.option('--cheese [type]', 'cheese type').option('--some-option');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 33why, one step back
33 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 back
34 assert.equal(program.opts().cheese, true);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 35–42why, one step back
35 });
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 back
43 program.option('--cheese [type]', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

line 45why, one step back
45 assert.equal(program.opts().cheese, defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 46–50why, one step back
46 });
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 back
51 program.option('--cheese [type]', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 52–53why, one step back
52 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 back
54 assert.equal(program.opts().cheese, cheeseType);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 55–59why, one step back
55 });
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 back
60 program.option('--cheese [type]', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 63–66why, one step back
63 });
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 back
67 program.addOption(new commander.Option('--cheese [type]').preset('preset'));

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

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

line 69why, one step back
69 assert.equal(program.opts().cheese, 'preset');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 70–71why, one step back
70 });
71});