Skip to content
Myr

options.required.test.js

This file

Path

tests/options.required.test.js

70 lines · 2.4 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–4why, one step back
1import * as commander from '../index.js';
2import { createTestCommand } from './testHelpers.js';3import { test, describe } from 'node:test';4import assert from 'node:assert/strict';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 5–6why, one step back
5
6// option with required value, no default

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 8–9why, one step back
8 test('when option not specified then value is undefined', () => {
9 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 10why, one step back
10 program.option('--cheese <type>', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 11why, one step back
11 program.parse(['node', 'test']);

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

line 12why, one step back
12 assert.equal(program.opts().cheese, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 13–16why, one step back
13 });
1415 test('when option specified then value is as specified', () => {16 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 17why, one step back
17 program.option('--cheese <type>', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 18–19why, one step back
18 const cheeseType = 'blue';
19 program.parse(['node', 'test', '--cheese', cheeseType]);

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

line 20why, one step back
20 assert.equal(program.opts().cheese, cheeseType);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 21–23why, one step back
21 });
2223 test('when option value not specified then error', () => {

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

line 24why, one step back
24 const program = createTestCommand();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 25why, one step back
25 program.option('--cheese <type>', 'cheese type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 26–27why, one step back
26
27 // Act. The throw is due to the above mock, and not default behaviour.

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

lines 28–35why, one step back
28 assert.throws(
29 () => {30 program.parse(['node', 'test', '--cheese']);31 },32 {33 code: 'commander.optionMissingArgument',34 },35 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 36–39why, one step back
36 });
37});3839// option with required value, with default

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

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

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 41–43why, one step back
41 test('when option not specified then value is default', () => {
42 const defaultValue = 'default';43 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 44why, one step back
44 program.option('--cheese <type>', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 45why, one step back
45 program.parse(['node', 'test']);

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

line 46why, one step back
46 assert.equal(program.opts().cheese, defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 47–51why, one step back
47 });
4849 test('when option specified then value is as specified', () => {50 const defaultValue = 'default';51 const program = new commander.Command();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 52why, one step back
52 program.option('--cheese <type>', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 53–54why, one step back
53 const cheeseType = 'blue';
54 program.parse(['node', 'test', '--cheese', cheeseType]);

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

line 55why, one step back
55 assert.equal(program.opts().cheese, cheeseType);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 56–57why, one step back
56 });
57

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

line 58why, one step back
58 test('when option value not specified then error', (t) => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 59why, one step back
59 const defaultValue = 'default';

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

line 60why, one step back
60 const program = createTestCommand();

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 61why, one step back
61 program.option('--cheese <type>', 'cheese type', defaultValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 62why, one step back
62

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

lines 63–68why, one step back
63 assert.throws(
64 () => {65 program.parse(['node', 'test', '--cheese']);66 },67 { code: 'commander.optionMissingArgument' },68 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 69–70why, one step back
69 });
70});