Skip to content
Myr

help.optionDescription.test.js

This file

Path

tests/help.optionDescription.test.js

103 lines · 3.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

lines 4–7why, one step back
4
5// These are tests of the Help class, not of the Command help.6// There is some overlap with the higher level Command tests (which predate Help).7

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

line 8why, one step back
8describe('Help.optionDescription()', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 9–11why, one step back
9 test('when option has no description then empty string', () => {
10 const option = new commander.Option('-a');11 const helper = new commander.Help();

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

line 12why, one step back
12 assert.equal(helper.optionDescription(option), '');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 13–18why, one step back
13 });
1415 test('when option has description then return description', () => {16 const description = 'description';17 const option = new commander.Option('-a', description);18 const helper = new commander.Help();

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

line 19why, one step back
19 assert.equal(helper.optionDescription(option), description);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 20–25why, one step back
20 });
2122 test('when boolean option has default value true then return description and default value', () => {23 const description = 'description';24 const option = new commander.Option('-a', description).default(true);25 const helper = new commander.Help();

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

lines 26–27why, one step back
26 assert.equal(
27 helper.optionDescription(option),

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 28–29why, one step back
28 'description (default: true)',
29 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 30–35why, one step back
30 });
3132 test('when boolean option has default value string then return description without default', () => {33 const description = 'description';34 const option = new commander.Option('-a', description).default('foo');35 const helper = new commander.Help();

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

line 36why, one step back
36 assert.equal(helper.optionDescription(option), 'description');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 37–40why, one step back
37 });
3839 test('when optional option has preset value then return description and default value', () => {40 const description = 'description';

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 41–43why, one step back
41 const option = new commander.Option('--aa [value]', description).preset(
42 'abc',43 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 44why, one step back
44 const helper = new commander.Help();

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

lines 45–46why, one step back
45 assert.equal(
46 helper.optionDescription(option),

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 47–48why, one step back
47 'description (preset: "abc")',
48 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 49–54why, one step back
49 });
5051 test('when boolean option has preset value then return description without default', () => {52 const description = 'description';53 const option = new commander.Option('--bb', description).preset('abc');54 const helper = new commander.Help();

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

line 55why, one step back
55 assert.equal(helper.optionDescription(option), 'description');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 56–60why, one step back
56 });
57 test('when option has env then return description and env name', () => {58 const description = 'description';59 const option = new commander.Option('-a', description).env('ENV');60 const helper = new commander.Help();

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

line 61why, one step back
61 assert.equal(helper.optionDescription(option), 'description (env: ENV)');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 62–66why, one step back
62 });
6364 test('when option has default value description then return description and custom default description', () => {65 const description = 'description';66 const defaultValueDescription = 'custom';

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 67–70why, one step back
67 const option = new commander.Option('-a <value>', description).default(
68 'default value',69 defaultValueDescription,70 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 71why, one step back
71 const helper = new commander.Help();

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

lines 72–73why, one step back
72 assert.equal(
73 helper.optionDescription(option),

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 74–75why, one step back
74 `description (default: ${defaultValueDescription})`,
75 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Trim description when there's only extra info (#2348)Misha Kaletskybefore adoption672e380

lines 78–84why, one step back
78 test('when option has default value but not description then return custom default', () => {
79 const defaultValueDescription = 'custom';80 const option = new commander.Option('-a <value>').default(81 'default value',82 defaultValueDescription,83 );84 const helper = new commander.Help();

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

lines 85–86why, one step back
85 assert.equal(
86 helper.optionDescription(option),

Trim description when there's only extra info (#2348)Misha Kaletskybefore adoption672e380

lines 87–90why, one step back
87 `(default: ${defaultValueDescription})`,
88 );89 });90

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 91–93why, one step back
91 test('when option has choices then return description and choices', () => {
92 const description = 'description';93 const choices = ['one', 'two'];

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 94–96why, one step back
94 const option = new commander.Option('-a <value>', description).choices(
95 choices,96 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 97why, one step back
97 const helper = new commander.Help();

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

lines 98–99why, one step back
98 assert.equal(
99 helper.optionDescription(option),

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 100–101why, one step back
100 'description (choices: "one", "two")',
101 );

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 102–103why, one step back
102 });
103});