Skip to content
Myr

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

lines 4–9why, one step back
4
5// 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 back
10// option with required value, using loop to test all matrix of values and tests

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

line 11why, one step back
11describe('option with required option-argument', () => {

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

lines 12–14why, one step back
12 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 back
15 function createPortProgram() {
16 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 17why, one step back
17 program.option('-p,--port <number>', 'specify port');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 18–20why, one step back
18 return program;
19 }20

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

line 21why, one step back
21 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 back
22 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 back
24 assert.equal(program.opts().port, value);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 25–26why, one step back
25 });
26

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

line 27why, one step back
27 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 back
28 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 back
30 assert.equal(program.opts().port, value);

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

line 33why, one step back
33 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 back
34 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 back
36 assert.equal(program.opts().port, value);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 37–38why, one step back
37 });
38

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

line 39why, one step back
39 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 back
40 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 back
42 assert.equal(program.opts().port, value);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 43why, one step back
43 });

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

lines 44–45why, one step back
44 }
45});

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 46–47why, one step back
46
47// option with optional value

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

line 48why, one step back
48describe('option with optional option-argument', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 49–50why, one step back
49 function createPortProgram() {
50 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 51why, one step back
51 program.option('-p,--port [number]', 'specify port');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 52–57why, one step back
52 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 back
58 assert.equal(program.opts().port, '80');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 59–63why, one step back
59 });
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 back
64 assert.equal(program.opts().port, '80');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 65–69why, one step back
65 });
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 back
70 assert.equal(program.opts().port, '80');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 71–75why, one step back
71 });
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 back
76 assert.equal(program.opts().port, '80');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 77–80why, one step back
77 });
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 back
81 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 back
85 program.parse(['node', 'test', '--cheese', '']);

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

line 86why, one step back
86 assert.equal(program.opts().cheese, '');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 87–88why, one step back
87 });
88});