Skip to content
Myr

commander.configureCommand.test.js

This file

Path

tests/commander.configureCommand.test.js

86 lines · 2.8 KiB · JavaScript

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than f47bdf5 point at it.

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 1–6why, one step back
1const commander = require('../');
23// Mostly testing direct on program, limited check that (sub)command working same.45// Default behaviours6

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 7why, one step back
7test('when default then options not stored on command', () => {

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 8–11why, one step back
8 const program = new commander.Command();
9 program10 .option('--foo <value>', 'description');11 program.parse(['node', 'test', '--foo', 'bar']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

lines 12–13why, one step back
12 expect(program.foo).toBeUndefined();
13 expect(program.opts().foo).toBe('bar');

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 14–15why, one step back
14});
15

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 16why, one step back
16test('when default then options+command passed to action', () => {

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 17–19why, one step back
17 const program = new commander.Command();
18 const callback = jest.fn();19 program

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

line 20why, one step back
20 .argument('<value>')

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 21–22why, one step back
21 .action(callback);
22 program.parse(['node', 'test', 'value']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 23why, one step back
23 expect(callback).toHaveBeenCalledWith('value', program.opts(), program);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 24–34why, one step back
24});
2526// storeOptionsAsProperties2728test('when storeOptionsAsProperties() then options stored on command', () => {29 const program = new commander.Command();30 program31 .storeOptionsAsProperties()32 .option('--foo <value>', 'description');33 program.parse(['node', 'test', '--foo', 'bar']);34 expect(program.foo).toBe('bar');

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 35why, one step back
35 expect(program.opts().foo).toBe('bar');

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 36–44why, one step back
36});
3738test('when storeOptionsAsProperties(true) then options stored on command', () => {39 const program = new commander.Command();40 program41 .storeOptionsAsProperties(true)42 .option('--foo <value>', 'description');43 program.parse(['node', 'test', '--foo', 'bar']);44 expect(program.foo).toBe('bar');

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 45why, one step back
45 expect(program.opts().foo).toBe('bar');

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 46–54why, one step back
46});
4748test('when storeOptionsAsProperties(false) then options not stored on command', () => {49 const program = new commander.Command();50 program51 .storeOptionsAsProperties(false)52 .option('--foo <value>', 'description');53 program.parse(['node', 'test', '--foo', 'bar']);54 expect(program.foo).toBeUndefined();

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 55why, one step back
55 expect(program.opts().foo).toBe('bar');

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

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

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 58why, one step back
58test('when storeOptionsAsProperties() then command+command passed to action', () => {

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 59–61why, one step back
59 const program = new commander.Command();
60 const callback = jest.fn();61 program

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 62why, one step back
62 .storeOptionsAsProperties()

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

line 63why, one step back
63 .argument('<value>')

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 64–65why, one step back
64 .action(callback);
65 program.parse(['node', 'test', 'value']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 66why, one step back
66 expect(callback).toHaveBeenCalledWith('value', program, program);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 67–68why, one step back
67});
68

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 69why, one step back
69test('when storeOptionsAsProperties(false) then opts+command passed to action', () => {

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 70–72why, one step back
70 const program = new commander.Command();
71 const callback = jest.fn();72 program

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 73why, one step back
73 .storeOptionsAsProperties(false)

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

line 74why, one step back
74 .argument('<value>')

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

lines 75–76why, one step back
75 .action(callback);
76 program.parse(['node', 'test', 'value']);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 77why, one step back
77 expect(callback).toHaveBeenCalledWith('value', program.opts(), program);

Tidy up example now check for required command arguments (#1320)John Geebefore adoptionf47bdf5

line 78why, one step back
78});

Increase test coverage, including incrementNodeInspectorPort (#1428)John Geebefore adoptiond8faba2

lines 79–86why, one step back
79
80test('when storeOptionsAsProperties() after adding option then throw', () => {81 const program = new commander.Command();82 program.option('--port <number>', 'port number', '80');83 expect(() => {84 program.storeOptionsAsProperties(false);85 }).toThrow();86});