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 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
line 4why, one step back4Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 5why, one step back5// Testing optsWithGlobals and getOptionValueSourceWithGlobals with focus on globals.Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 6why, one step back6Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 7why, one step back7describe('Command.optsWithGlobals()', () => {Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 8–15why, one step back8 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 back16Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 17why, one step back17 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 back18 assert.deepEqual(program.opts(), program.optsWithGlobals());Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 19why, one step back19 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 20why, one step back20Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 21–23why, one step back21 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 back24 program.option('-g, --global <value>');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 25–30why, one step back25 program26 .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 back31Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 32why, one step back32 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 back33 assert.deepEqual(mergedOptions, { global: 'GGG', local: 'LLL' });Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 34why, one step back34 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 35why, one step back35Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 36–47why, one step back36 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 });47Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 48–50why, one step back48 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 back51 assert.deepEqual(mergedOptions, { global: 'GGG', local: 'LLL' });Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 52–56why, one step back52 });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 back57 program.option('-c, --common <value>').enablePositionalOptions();Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 58–65why, one step back58 program59 .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 back66 assert.deepEqual(mergedOptions, { common: 'GGG' });Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 67why, one step back67 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 68–69why, one step back68});69Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 70–72why, one step back70describe('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 back73 program.option('-g, --global');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 74why, one step back74Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 75why, one step back75 program.parse(['-g'], { from: 'user' });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.equal(program.getOptionValueSourceWithGlobals('global'), 'cli');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 77–80why, one step back77 });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 back81 program.option('-g, --global');82 const sub = program83 .command('sub')Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 84–87why, one step back84 .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 back88 assert.equal(sub.getOptionValueSourceWithGlobals('global'), 'cli');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 89–92why, one step back89 });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 back93 program.option('-g, --global');94 const sub = program95 .command('sub')Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 96–99why, one step back96 .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 back100 assert.equal(sub.getOptionValueSourceWithGlobals('local'), 'cli');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 101–107why, one step back101 });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 back108 const sub = program109 .command('sub')Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 110–113why, one step back110 .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 back114 assert.equal(sub.getOptionValueSourceWithGlobals('common'), 'default');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
line 115why, one step back115 });Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 116why, one step back116});