options.values.test.js
This file
Path
tests/options.values.test.js
88 lines · 3.3 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–9why, one step back45// Test the ways values can be specified for options.6// See also references on "Utility Conventions" in command.parseOptions.test.js78// options with required values can eat values starting with a dash, including just dash sometimes used as alias for stdin9//Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 10why, one step back10// option with required value, using loop to test all matrix of values and testsAdd describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 11why, one step back11describe('option with required option-argument', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 12–14why, one step back12 const valuesList = [['str'], ['80'], ['-'], ['-5'], ['--flag']];1314 for (const [value] of valuesList) {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 15–16why, one step back15 function createPortProgram() {16 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 17why, one step back17 program.option('-p,--port <number>', 'specify port');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–20why, one step back18 return program;19 }20Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 21why, one step back21 test(`when option with required value specified as ${value} and short flag followed by value then value is as specified`, () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 22–23why, one step back22 const program = createPortProgram();23 program.parse(['node', 'test', '-p', value]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 24why, one step back24 assert.equal(program.opts().port, value);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 25–26why, one step back25 });26Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 27why, one step back27 test(`when option with required value specified as ${value} and short flag concatenated with value then value is as specified`, () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 28–29why, one step back28 const program = createPortProgram();29 program.parse(['node', 'test', `-p${value}`]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 30why, one step back30 assert.equal(program.opts().port, value);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 31–32why, one step back31 });32Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 33why, one step back33 test(`when option with required value specified as ${value} and long flag followed by value then value is as specified`, () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 34–35why, one step back34 const program = createPortProgram();35 program.parse(['node', 'test', '--port', value]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 36why, one step back36 assert.equal(program.opts().port, value);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 37–38why, one step back37 });38Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 39why, one step back39 test(`when option with required value specified as ${value} and long flag = value then value is as specified`, () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 40–41why, one step back40 const program = createPortProgram();41 program.parse(['node', 'test', `--port=${value}`]);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 42why, one step back42 assert.equal(program.opts().port, value);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 43why, one step back43 });Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 44–45why, one step back44 }45});Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 46–47why, one step back4647// option with optional valueAdd describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
line 48why, one step back48describe('option with optional option-argument', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 49–50why, one step back49 function createPortProgram() {50 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 51why, one step back51 program.option('-p,--port [number]', 'specify port');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 52–57why, one step back52 return program;53 }5455 test('when short flag followed by value then value is as specified', () => {56 const program = createPortProgram();57 program.parse('node test -p 80'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 58why, one step back58 assert.equal(program.opts().port, '80');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 59–63why, one step back59 });6061 test('when short flag concatenated with value then value is as specified', () => {62 const program = createPortProgram();63 program.parse('node test -p80'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 64why, one step back64 assert.equal(program.opts().port, '80');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 65–69why, one step back65 });6667 test('when long flag followed by value then value is as specified', () => {68 const program = createPortProgram();69 program.parse('node test --port 80'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 70why, one step back70 assert.equal(program.opts().port, '80');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 71–75why, one step back71 });7273 test('when long flag = value then value is as specified', () => {74 const program = createPortProgram();75 program.parse('node test --port=80'.split(' '));Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.equal(program.opts().port, '80');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 77–80why, one step back77 });7879 test('when long flag followed empty string then value is empty string', () => {80 const program = createPortProgram();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 81–84why, one step back81 program.option(82 '-c, --cheese [type]',83 'optionally specify the type of cheese',84 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 85why, one step back85 program.parse(['node', 'test', '--cheese', '']);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 86why, one step back86 assert.equal(program.opts().cheese, '');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 87–88why, one step back87 });88});