Skip to content
Myr

command.copySettings.test.js

This file

Path

tests/command.copySettings.test.js

150 lines · 5.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–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// Tests some private properties as simpler than pure tests of observable behaviours.6// Testing before and after values in some cases, to ensure value actually changes (when copied).7

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

lines 8–10why, one step back
8describe('Command.copyInheritedSettings()', () => {
9 test('when add subcommand with .command() then calls copyInheritedSettings from parent', (t) => {10 const program = new commander.Command();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 11why, one step back
11

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

lines 12–19why, one step back
12 // This is a bit intrusive, but check expectation that copyInheritedSettings is called internally.
13 const copySettingMock = t.mock.fn();14 program.createCommand = (name) => {15 const cmd = new commander.Command(name);16 cmd.copyInheritedSettings = copySettingMock;17 return cmd;18 };19 program.command('sub');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 20why, one step back
20

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

lines 21–23why, one step back
21 const callArgs = copySettingMock.mock.calls[0].arguments;
22 assert.equal(callArgs[0], program);23 });

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 24–30why, one step back
24
25 test('when copyInheritedSettings then copies outputConfiguration(config)', () => {26 const source = new commander.Command();27 const cmd = new commander.Command();2829 source.configureOutput({ foo: 'bar' });30 cmd.copyInheritedSettings(source);

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

line 31why, one step back
31 assert.equal(cmd.configureOutput().foo, 'bar');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 32–39why, one step back
32 });
3334 test('when copyInheritedSettings then copies helpOption(false)', () => {35 const source = new commander.Command();36 const cmd = new commander.Command();3738 source.helpOption(false);39 cmd.copyInheritedSettings(source);

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

line 40why, one step back
40 assert.equal(cmd._getHelpOption(), null);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 41–48why, one step back
41 });
4243 test('when copyInheritedSettings then copies helpOption(flags, description)', () => {44 const source = new commander.Command();45 const cmd = new commander.Command();4647 source.helpOption('-Z, --zz', 'ddd');48 cmd.copyInheritedSettings(source);

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

line 49why, one step back
49 assert.equal(cmd._getHelpOption(), source._getHelpOption());

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 50–54why, one step back
50 // const helpOption = cmd._getHelpOption();
51 // expect(helpOption.flags).toBe('-Z, --zz');52 // expect(helpOption.description).toBe('ddd');53 // expect(helpOption.short).toBe('-Z');54 // expect(helpOption.long).toBe('--zz');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 57why, one step back
57 test('when copyInheritedSettings then copies custom help command', () => {

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 58–60why, one step back
58 const source = new commander.Command();
59 const cmd = new commander.Command();60

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

line 61why, one step back
61 source.helpCommand('HELP [cmd]', 'ddd');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 62why, one step back
62 cmd.copyInheritedSettings(source);

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 63–64why, one step back
63 cmd.helpCommand(true); // force enable
64 const helpCommand = cmd._getHelpCommand();

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

lines 65–67why, one step back
65 assert.ok(helpCommand);
66 assert.equal(helpCommand.name(), 'HELP');67 assert.equal(helpCommand.description(), 'ddd');

Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1

lines 68–77why, one step back
68 });
6970 test('when copyInheritedSettings then does not copy help enable override', () => {71 const source = new commander.Command();72 const cmd = new commander.Command();7374 // Existing behaviour, force enable/disable does not inherit,75 // largely so (probably redundant) program.helpCommand(true) does not inherit to leaf subcommands.76 source.helpCommand(true);77 cmd.copyInheritedSettings(source);

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

line 78why, one step back
78 assert.equal(cmd._addHelpOption, undefined);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 79–87why, one step back
79 });
8081 test('when copyInheritedSettings then copies configureHelp(config)', () => {82 const source = new commander.Command();83 const cmd = new commander.Command();8485 const configuration = { foo: 'bar', helpWidth: 123, sortSubcommands: true };86 source.configureHelp(configuration);87 cmd.copyInheritedSettings(source);

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

line 88why, one step back
88 assert.deepEqual(cmd.configureHelp(), configuration);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 89–94why, one step back
89 });
9091 test('when copyInheritedSettings then copies exitOverride()', () => {92 const source = new commander.Command();93 const cmd = new commander.Command();94

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

line 95why, one step back
95 assert.ok(!cmd._exitCallback);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 96–97why, one step back
96 source.exitOverride();
97 cmd.copyInheritedSettings(source);

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

line 98why, one step back
98 assert.ok(cmd._exitCallback); // actually a function

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 99–104why, one step back
99 });
100101 test('when copyInheritedSettings then copies storeOptionsAsProperties()', () => {102 const source = new commander.Command();103 const cmd = new commander.Command();104

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

line 105why, one step back
105 assert.ok(!cmd._storeOptionsAsProperties);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 106–107why, one step back
106 source.storeOptionsAsProperties();
107 cmd.copyInheritedSettings(source);

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

line 108why, one step back
108 assert.ok(cmd._storeOptionsAsProperties);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 109–114why, one step back
109 });
110111 test('when copyInheritedSettings then copies combineFlagAndOptionalValue()', () => {112 const source = new commander.Command();113 const cmd = new commander.Command();114

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

line 115why, one step back
115 assert.ok(cmd._combineFlagAndOptionalValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 116–117why, one step back
116 source.combineFlagAndOptionalValue(false);
117 cmd.copyInheritedSettings(source);

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

line 118why, one step back
118 assert.ok(!cmd._combineFlagAndOptionalValue);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 119–124why, one step back
119 });
120121 test('when copyInheritedSettings then copies allowExcessArguments()', () => {122 const source = new commander.Command();123 const cmd = new commander.Command();124

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

line 125why, one step back
125 assert.ok(!cmd._allowExcessArguments);

Disallow excess arguments (#2223)John Geebefore adoption58c28eb

lines 126–127why, one step back
126 source.allowExcessArguments();
127 cmd.copyInheritedSettings(source);

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

line 128why, one step back
128 assert.ok(cmd._allowExcessArguments);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 129–134why, one step back
129 });
130131 test('when copyInheritedSettings then copies enablePositionalOptions()', () => {132 const source = new commander.Command();133 const cmd = new commander.Command();134

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

line 135why, one step back
135 assert.ok(!cmd._enablePositionalOptions);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 136–137why, one step back
136 source.enablePositionalOptions();
137 cmd.copyInheritedSettings(source);

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

line 138why, one step back
138 assert.ok(cmd._enablePositionalOptions);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 139–144why, one step back
139 });
140141 test('when copyInheritedSettings then copies showHelpAfterError()', () => {142 const source = new commander.Command();143 const cmd = new commander.Command();144

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

line 145why, one step back
145 assert.ok(!cmd._showHelpAfterError);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 146–147why, one step back
146 source.showHelpAfterError();
147 cmd.copyInheritedSettings(source);

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

line 148why, one step back
148 assert.ok(cmd._showHelpAfterError);

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 149–150why, one step back
149 });
150});