Skip to content
Myr

options.optsWithGlobals.test.js

This file

Path

tests/options.optsWithGlobals.test.js

116 lines · 3.9 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

line 4why, one step back
4

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 5why, one step back
5// Testing optsWithGlobals and getOptionValueSourceWithGlobals with focus on globals.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 6why, one step back
6

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

line 7why, one step back
7describe('Command.optsWithGlobals()', () => {

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 8–15why, one step back
8 test('when variety of options used with program then opts is same as optsWithGlobals', () => {
9 const program = new commander.Command();10 program11 .option('-b, --boolean')12 .option('-r, --require-value <value)')13 .option('-f, --float <value>', 'description', parseFloat)14 .option('-d, --default-value <value)', 'description', 'default value')15 .option('-n, --no-something');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 16why, one step back
16

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 17why, one step back
17 program.parse(['-b', '-r', 'req', '-f', '1e2'], { from: 'user' });

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

line 18why, one step back
18 assert.deepEqual(program.opts(), program.optsWithGlobals());

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 19why, one step back
19 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 20why, one step back
20

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 21–23why, one step back
21 test('when options in sub and program then optsWithGlobals includes both', () => {
22 const program = new commander.Command();23 let mergedOptions;

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 24why, one step back
24 program.option('-g, --global <value>');

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 25–30why, one step back
25 program
26 .command('sub')27 .option('-l, --local <value)')28 .action((options, cmd) => {29 mergedOptions = cmd.optsWithGlobals();30 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 31why, one step back
31

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 32why, one step back
32 program.parse(['-g', 'GGG', 'sub', '-l', 'LLL'], { from: 'user' });

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

line 33why, one step back
33 assert.deepEqual(mergedOptions, { global: 'GGG', local: 'LLL' });

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 34why, one step back
34 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 35why, one step back
35

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 36–47why, one step back
36 test('when options in sub and subsub then optsWithGlobals includes both', () => {
37 const program = new commander.Command();38 let mergedOptions;39 program40 .command('sub')41 .option('-g, --global <value)')42 .command('subsub')43 .option('-l, --local <value)')44 .action((options, cmd) => {45 mergedOptions = cmd.optsWithGlobals();46 });47

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 48–50why, one step back
48 program.parse(['sub', '-g', 'GGG', 'subsub', '-l', 'LLL'], {
49 from: 'user',50 });

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

line 51why, one step back
51 assert.deepEqual(mergedOptions, { global: 'GGG', local: 'LLL' });

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 52–56why, one step back
52 });
5354 test('when same named option in sub and program then optsWithGlobals includes global', () => {55 const program = new commander.Command();56 let mergedOptions;

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 57why, one step back
57 program.option('-c, --common <value>').enablePositionalOptions();

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 58–65why, one step back
58 program
59 .command('sub')60 .option('-c, --common <value)')61 .action((options, cmd) => {62 mergedOptions = cmd.optsWithGlobals();63 });6465 program.parse(['-c', 'GGG', 'sub', '-c', 'LLL'], { from: 'user' });

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

line 66why, one step back
66 assert.deepEqual(mergedOptions, { common: 'GGG' });

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 67why, one step back
67 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 68–69why, one step back
68});
69

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 70–72why, one step back
70describe('getOptionValueSourceWithGlobals', () => {
71 test('when option used with simple command then source is defined', () => {72 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 73why, one step back
73 program.option('-g, --global');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 74why, one step back
74

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 75why, one step back
75 program.parse(['-g'], { from: 'user' });

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

line 76why, one step back
76 assert.equal(program.getOptionValueSourceWithGlobals('global'), 'cli');

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 77–80why, one step back
77 });
7879 test('when option used with program then source is defined', () => {80 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 81–83why, one step back
81 program.option('-g, --global');
82 const sub = program83 .command('sub')

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 84–87why, one step back
84 .option('-l, --local')
85 .action(() => {});8687 program.parse(['sub', '-g'], { from: 'user' });

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

line 88why, one step back
88 assert.equal(sub.getOptionValueSourceWithGlobals('global'), 'cli');

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 89–92why, one step back
89 });
9091 test('when option used with subcommand then source is defined', () => {92 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 93–95why, one step back
93 program.option('-g, --global');
94 const sub = program95 .command('sub')

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 96–99why, one step back
96 .option('-l, --local')
97 .action(() => {});9899 program.parse(['sub', '-l'], { from: 'user' });

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

line 100why, one step back
100 assert.equal(sub.getOptionValueSourceWithGlobals('local'), 'cli');

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 101–107why, one step back
101 });
102103 test('when same named option in sub and program then source is defined by global', () => {104 const program = new commander.Command();105 program106 .enablePositionalOptions()107 .option('-c, --common <value>', 'description', 'default value');

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 108–109why, one step back
108 const sub = program
109 .command('sub')

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 110–113why, one step back
110 .option('-c, --common <value>')
111 .action(() => {});112113 program.parse(['sub', '--common', 'value'], { from: 'user' });

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

line 114why, one step back
114 assert.equal(sub.getOptionValueSourceWithGlobals('common'), 'default');

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

line 115why, one step back
115 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 116why, one step back
116});