Skip to content
Myr

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 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

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

line 5why, one step back
5// Testing variadic arguments.

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 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 back
8 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 back
10 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 11why, one step back
11 program.arguments('<id> [variadicArg...]').action(actionMock);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 12–14why, one step back
12
13 program.parse(['node', 'test', 'id']);14

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

lines 15–17why, one step back
15 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 back
18 });
19

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

lines 20–21why, one step back
20 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 back
22 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 23why, one step back
23 program.arguments('<id> [variadicArg...]').action(actionMock);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 24–27why, one step back
24 const extraArguments = ['a', 'b', 'c'];
2526 program.parse(['node', 'test', 'id', ...extraArguments]);27

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

lines 28–30why, one step back
28 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 back
31 });
32

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

lines 33–34why, one step back
33 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 back
35 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 36why, one step back
36 const cmd = program.command('sub [variadicArg...]').action(actionMock);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 37–39why, one step back
37
38 program.parse(['node', 'test', 'sub']);39

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

lines 40–41why, one step back
40 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 back
42 });
43

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

lines 44–45why, one step back
44 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 back
46 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 47why, one step back
47 const cmd = program.command('sub [variadicArg...]').action(actionMock);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 48–51why, one step back
48 const extraArguments = ['a', 'b', 'c'];
4950 program.parse(['node', 'test', 'sub', ...extraArguments]);51

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

lines 52–53why, one step back
52 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 back
54 });
5556 test('when program variadic argument not last then error', () => {57 const program = new commander.Command();58

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

line 59why, one step back
59 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 60why, one step back
60 program.arguments('<variadicArg...> [optionalArg]');

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

line 61why, one step back
61 }, /only the last argument can be variadic 'variadicArg'/);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 62–66why, one step back
62 });
6364 test('when command variadic argument not last then error', () => {65 const program = new commander.Command();66

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

line 67why, one step back
67 assert.throws(() => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 68why, one step back
68 program.command('sub <variadicArg...> [optionalArg]');

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

line 69why, one step back
69 }, /only the last argument can be variadic 'variadicArg'/);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 70–73why, one step back
70 });
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 back
74 program.name('foo').arguments('[args...]');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 75why, one step back
75

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

line 76why, one step back
76 assert.equal(program.usage(), '[options] [args...]');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 77–78why, one step back
77 });
78});