Skip to content
Myr

command.chain.test.js

This file

Path

tests/command.chain.test.js

211 lines · 6.6 KiB · JavaScript

Last changed by

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

History of this file

Take it

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 1why, one step back
1const { Command, Option, Argument } = require('../');

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 2–15why, one step back
2
3// Testing the functions which should chain.4// parse and parseAsync are tested in command.parse.test.js56describe('Command methods that should return this for chaining', () => {7 test('when call .command() with description for stand-alone executable then returns this', () => {8 const program = new Command();9 const result = program.command('foo', 'foo description');10 expect(result).toBe(program);11 });1213 test('when call .addCommand() then returns this', () => {14 const program = new Command();15 const result = program.addCommand(new Command('name'));

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

lines 16–27why, one step back
16 expect(result).toBe(program);
17 });1819 test('when call .argument() then returns this', () => {20 const program = new Command();21 const result = program.argument('<file>');22 expect(result).toBe(program);23 });2425 test('when call .addArgument() then returns this', () => {26 const program = new Command();27 const result = program.addArgument(new Argument('<file>'));

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 28–84why, one step back
28 expect(result).toBe(program);
29 });3031 test('when set .arguments() then returns this', () => {32 const program = new Command();33 const result = program.arguments('<file>');34 expect(result).toBe(program);35 });3637 test('when call .addHelpCommand() then returns this', () => {38 const program = new Command();39 const result = program.addHelpCommand(false);40 expect(result).toBe(program);41 });4243 test('when call .exitOverride() then returns this', () => {44 const program = new Command();45 const result = program.exitOverride(() => { });46 expect(result).toBe(program);47 });4849 test('when call .action() then returns this', () => {50 const program = new Command();51 const result = program.action(() => { });52 expect(result).toBe(program);53 });5455 test('when call .addOption() then returns this', () => {56 const program = new Command();57 const result = program.addOption(new Option('-e'));58 expect(result).toBe(program);59 });6061 test('when call .option() then returns this', () => {62 const program = new Command();63 const result = program.option('-e');64 expect(result).toBe(program);65 });6667 test('when call .requiredOption() then returns this', () => {68 const program = new Command();69 const result = program.requiredOption('-r');70 expect(result).toBe(program);71 });7273 test('when call .combineFlagAndOptionalValue() then returns this', () => {74 const program = new Command();75 const result = program.combineFlagAndOptionalValue();76 expect(result).toBe(program);77 });7879 test('when call .allowUnknownOption() then returns this', () => {80 const program = new Command();81 const result = program.allowUnknownOption();82 expect(result).toBe(program);83 });84

Add .allowExcessArguments() and error message (#1407)John Geebefore adoption09f277a

lines 85–90why, one step back
85 test('when call .allowExcessArguments() then returns this', () => {
86 const program = new Command();87 const result = program.allowExcessArguments();88 expect(result).toBe(program);89 });90

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 91–143why, one step back
91 test('when call .storeOptionsAsProperties() then returns this', () => {
92 const program = new Command();93 const result = program.storeOptionsAsProperties();94 expect(result).toBe(program);95 });9697 test('when call .version() then returns this', () => {98 const program = new Command();99 const result = program.version('1.2.3');100 expect(result).toBe(program);101 });102103 test('when set .description() then returns this', () => {104 const program = new Command();105 const result = program.description('description');106 expect(result).toBe(program);107 });108109 test('when set .alias() then returns this', () => {110 const program = new Command();111 const result = program.alias('alias');112 expect(result).toBe(program);113 });114115 test('when set .aliases() then returns this', () => {116 const program = new Command();117 const result = program.aliases(['foo', 'bar']);118 expect(result).toBe(program);119 });120121 test('when set .usage() then returns this', () => {122 const program = new Command();123 const result = program.usage('[options]');124 expect(result).toBe(program);125 });126127 test('when set .name() then returns this', () => {128 const program = new Command();129 const result = program.name('easy');130 expect(result).toBe(program);131 });132133 test('when call .helpOption() then returns this', () => {134 const program = new Command();135 const result = program.helpOption(false);136 expect(result).toBe(program);137 });138139 test('when call .addHelpText() then returns this', () => {140 const program = new Command();141 const result = program.addHelpText('before', 'example');142 expect(result).toBe(program);143 });

Refactor help internals into separate interface/class (#1365)John Geebefore adoption19ae912

lines 144–149why, one step back
144
145 test('when call .configureHelp() then returns this', () => {146 const program = new Command();147 const result = program.configureHelp({ });148 expect(result).toBe(program);149 });

configure output (#1387)John Geebefore adoptioned7f13e

lines 150–155why, one step back
150
151 test('when call .configureOutput() then returns this', () => {152 const program = new Command();153 const result = program.configureOutput({ });154 expect(result).toBe(program);155 });

Positional options (#1427)John Geebefore adoption8ac84ec

lines 156–167why, one step back
156
157 test('when call .passThroughOptions() then returns this', () => {158 const program = new Command();159 const result = program.passThroughOptions();160 expect(result).toBe(program);161 });162163 test('when call .enablePositionalOptions() then returns this', () => {164 const program = new Command();165 const result = program.enablePositionalOptions();166 expect(result).toBe(program);167 });

Add getOptionValue and setOptionValue (#1521)John Geebefore adoption6c06528

line 168why, one step back
168

Add hooks for life cycle events: using .hook() (#1514)John Geebefore adoptionc20284d

lines 169–174why, one step back
169 test('when call .hook() then returns this', () => {
170 const program = new Command();171 const result = program.hook('preAction', () => {});172 expect(result).toBe(program);173 });174

Add getOptionValue and setOptionValue (#1521)John Geebefore adoption6c06528

lines 175–176why, one step back
175 test('when call .setOptionValue() then returns this', () => {
176 const program = new Command();

Add setOptionValueWithSource and getOptionValueSource (#1613)John Geebefore adoption6e00f44

lines 177–183why, one step back
177 const result = program.setOptionValue('foo', 'bar');
178 expect(result).toBe(program);179 });180181 test('when call .setOptionValueWithSource() then returns this', () => {182 const program = new Command();183 const result = program.setOptionValueWithSource('foo', 'bar', 'cli');

Add getOptionValue and setOptionValue (#1521)John Geebefore adoption6c06528

lines 184–185why, one step back
184 expect(result).toBe(program);
185 });

Add showHelpAfterError (#1534)John Geebefore adoption082717f

lines 186–191why, one step back
186
187 test('when call .showHelpAfterError() then returns this', () => {188 const program = new Command();189 const result = program.showHelpAfterError();190 expect(result).toBe(program);191 });

Add copyInheritedSettings (#1557)John Geebefore adoption5517d25

line 192why, one step back
192

Suggestion for unknown command and unknown option (#1590)John Geebefore adoption91ccfd5

lines 193–198why, one step back
193 test('when call .showSuggestionAfterError() then returns this', () => {
194 const program = new Command();195 const result = program.showSuggestionAfterError();196 expect(result).toBe(program);197 });198

Add copyInheritedSettings (#1557)John Geebefore adoption5517d25

lines 199–204why, one step back
199 test('when call .copyInheritedSettings() then returns this', () => {
200 const program = new Command();201 const cmd = new Command();202 const result = cmd.copyInheritedSettings(program);203 expect(result).toBe(cmd);204 });

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

lines 205–210why, one step back
205
206 test('when set .nameFromFilename() then returns this', () => {207 const program = new Command();208 const result = program.nameFromFilename('name');209 expect(result).toBe(program);210 });

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

line 211why, one step back
211});