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 fileTake 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 back1import * 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 back45// 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).7Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 8–10why, one step back8describe('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 back11Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 12–19why, one step back12 // 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 back20Add describe wrappers so test output makes sense without filenames (#2472)John Geebefore adoptionb3e6795
lines 21–23why, one step back21 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 back2425 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 back31 assert.equal(cmd.configureOutput().foo, 'bar');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 32–39why, one step back32 });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 back40 assert.equal(cmd._getHelpOption(), null);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 41–48why, one step back41 });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 back49 assert.equal(cmd._getHelpOption(), source._getHelpOption());Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 50–54why, one step back50 // 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 back55 });56Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 57why, one step back57 test('when copyInheritedSettings then copies custom help command', () => {Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 58–60why, one step back58 const source = new commander.Command();59 const cmd = new commander.Command();60Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
line 61why, one step back61 source.helpCommand('HELP [cmd]', 'ddd');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 62why, one step back62 cmd.copyInheritedSettings(source);Merge pull request #2140 from tj/release/12.xJohn Geebefore adoptione3192a1
lines 63–64why, one step back63 cmd.helpCommand(true); // force enable64 const helpCommand = cmd._getHelpCommand();Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
lines 65–67why, one step back65 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 back68 });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 back78 assert.equal(cmd._addHelpOption, undefined);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 79–87why, one step back79 });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 back88 assert.deepEqual(cmd.configureHelp(), configuration);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 89–94why, one step back89 });9091 test('when copyInheritedSettings then copies exitOverride()', () => {92 const source = new commander.Command();93 const cmd = new commander.Command();94Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 95why, one step back95 assert.ok(!cmd._exitCallback);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 96–97why, one step back96 source.exitOverride();97 cmd.copyInheritedSettings(source);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 98why, one step back98 assert.ok(cmd._exitCallback); // actually a functionAdd copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 99–104why, one step back99 });100101 test('when copyInheritedSettings then copies storeOptionsAsProperties()', () => {102 const source = new commander.Command();103 const cmd = new commander.Command();104Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 105why, one step back105 assert.ok(!cmd._storeOptionsAsProperties);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 106–107why, one step back106 source.storeOptionsAsProperties();107 cmd.copyInheritedSettings(source);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 108why, one step back108 assert.ok(cmd._storeOptionsAsProperties);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 109–114why, one step back109 });110111 test('when copyInheritedSettings then copies combineFlagAndOptionalValue()', () => {112 const source = new commander.Command();113 const cmd = new commander.Command();114Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 115why, one step back115 assert.ok(cmd._combineFlagAndOptionalValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 116–117why, one step back116 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 back118 assert.ok(!cmd._combineFlagAndOptionalValue);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 119–124why, one step back119 });120121 test('when copyInheritedSettings then copies allowExcessArguments()', () => {122 const source = new commander.Command();123 const cmd = new commander.Command();124Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 125why, one step back125 assert.ok(!cmd._allowExcessArguments);Disallow excess arguments (#2223)John Geebefore adoption58c28eb
lines 126–127why, one step back126 source.allowExcessArguments();127 cmd.copyInheritedSettings(source);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 128why, one step back128 assert.ok(cmd._allowExcessArguments);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 129–134why, one step back129 });130131 test('when copyInheritedSettings then copies enablePositionalOptions()', () => {132 const source = new commander.Command();133 const cmd = new commander.Command();134Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 135why, one step back135 assert.ok(!cmd._enablePositionalOptions);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 136–137why, one step back136 source.enablePositionalOptions();137 cmd.copyInheritedSettings(source);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 138why, one step back138 assert.ok(cmd._enablePositionalOptions);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 139–144why, one step back139 });140141 test('when copyInheritedSettings then copies showHelpAfterError()', () => {142 const source = new commander.Command();143 const cmd = new commander.Command();144Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 145why, one step back145 assert.ok(!cmd._showHelpAfterError);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 146–147why, one step back146 source.showHelpAfterError();147 cmd.copyInheritedSettings(source);Switch from Jest to Node.js built-in test runner (#2463)John Geebefore adoption3dd6086
line 148why, one step back148 assert.ok(cmd._showHelpAfterError);Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 149–150why, one step back149 });150});