args.variadic.test.js
This file
Path
tests/args.variadic.test.js
78 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
line 4why, one step back4Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 5why, one step back5// Testing variadic arguments.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 variadic argument using .arguments() or .command()', () => {Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 8–9why, one step back8 test('when no extra arguments specified for program then variadic arg is empty array', (t) => {9 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 10why, one step back10 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 11why, one step back11 program.arguments('<id> [variadicArg...]').action(actionMock);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 12–14why, one step back1213 program.parse(['node', 'test', 'id']);14Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 15–17why, one step back15 const callArgs = actionMock.mock.calls[0].arguments;16 assert.equal(callArgs[0], 'id');17 assert.deepEqual(callArgs[1], []);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 18–19why, one step back18 });19Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 20–21why, one step back20 test('when extra arguments specified for program then variadic arg is array of values', (t) => {21 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 22why, one step back22 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 23why, one step back23 program.arguments('<id> [variadicArg...]').action(actionMock);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 24–27why, one step back24 const extraArguments = ['a', 'b', 'c'];2526 program.parse(['node', 'test', 'id', ...extraArguments]);27Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 28–30why, one step back28 const callArgs = actionMock.mock.calls[0].arguments;29 assert.equal(callArgs[0], 'id');30 assert.deepEqual(callArgs[1], extraArguments);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
lines 33–34why, one step back33 test('when no extra arguments specified for command then variadic arg is empty array', (t) => {34 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 35why, one step back35 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 36why, one step back36 const cmd = program.command('sub [variadicArg...]').action(actionMock);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 37–39why, one step back3738 program.parse(['node', 'test', 'sub']);39Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 40–41why, one step back40 const callArgs = actionMock.mock.calls[0].arguments;41 assert.deepEqual(callArgs[0], []);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 42–43why, one step back42 });43Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 44–45why, one step back44 test('when extra arguments specified for command then variadic arg is array of values', (t) => {45 const actionMock = t.mock.fn();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 46why, one step back46 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 47why, one step back47 const cmd = program.command('sub [variadicArg...]').action(actionMock);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 48–51why, one step back48 const extraArguments = ['a', 'b', 'c'];4950 program.parse(['node', 'test', 'sub', ...extraArguments]);51Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 52–53why, one step back52 const callArgs = actionMock.mock.calls[0].arguments;53 assert.deepEqual(callArgs[0], extraArguments);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 54–58why, one step back54 });5556 test('when program variadic argument not last then error', () => {57 const program = new commander.Command();58Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 59why, one step back59 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 60why, one step back60 program.arguments('<variadicArg...> [optionalArg]');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 61why, one step back61 }, /only the last argument can be variadic 'variadicArg'/);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 62–66why, one step back62 });6364 test('when command variadic argument not last then error', () => {65 const program = new commander.Command();66Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 67why, one step back67 assert.throws(() => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 68why, one step back68 program.command('sub <variadicArg...> [optionalArg]');Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 69why, one step back69 }, /only the last argument can be variadic 'variadicArg'/);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 70–73why, one step back70 });7172 test('when variadic argument then usage shows variadic', () => {73 const program = new commander.Command();Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 74why, one step back74 program.name('foo').arguments('[args...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 75why, one step back75Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 76why, one step back76 assert.equal(program.usage(), '[options] [args...]');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 77–78why, one step back77 });78});