Skip to content
Myr

options.values.test.js

This file

Path

tests/options.values.test.js

83 lines · 3.0 KiB · JavaScript

Last changed by

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

History of this file

Take it

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

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 1–20why, one step back
1const commander = require('../');
23// Test the ways values can be specified for options.4// See also references on "Utility Conventions" in command.parseOptions.test.js56// options with required values can eat values starting with a dash, including just dash sometimes used as alias for stdin7//8// option with required value, using describe.each to test all matrix of values and tests9describe.each([['str'], ['80'], ['-'], ['-5'], ['--flag']])(10 'option with required value specified as %s', (value) => {11 function createPortProgram() {12 const program = new commander.Command();13 program14 .option('-p,--port <number>', 'specify port');15 return program;16 }1718 test('when short flag followed by value then value is as specified', () => {19 const program = createPortProgram();20 program.parse(['node', 'test', '-p', value]);

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

line 21why, one step back
21 expect(program.opts().port).toBe(value);

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 22–26why, one step back
22 });
2324 test('when short flag concatenated with value then value is as specified', () => {25 const program = createPortProgram();26 program.parse(['node', 'test', `-p${value}`]);

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

line 27why, one step back
27 expect(program.opts().port).toBe(value);

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 28–32why, one step back
28 });
2930 test('when long flag followed by value then value is as specified', () => {31 const program = createPortProgram();32 program.parse(['node', 'test', '--port', value]);

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

line 33why, one step back
33 expect(program.opts().port).toBe(value);

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 34–38why, one step back
34 });
3536 test('when long flag = value then value is as specified', () => {37 const program = createPortProgram();38 program.parse(['node', 'test', `--port=${value}`]);

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

line 39why, one step back
39 expect(program.opts().port).toBe(value);

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 40–54why, one step back
40 });
41 });4243// option with optional value44describe('option with optional value', () => {45 function createPortProgram() {46 const program = new commander.Command();47 program48 .option('-p,--port [number]', 'specify port');49 return program;50 }5152 test('when short flag followed by value then value is as specified', () => {53 const program = createPortProgram();54 program.parse('node test -p 80'.split(' '));

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().port).toBe('80');

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 56–60why, one step back
56 });
5758 test('when short flag concatenated with value then value is as specified', () => {59 const program = createPortProgram();60 program.parse('node test -p80'.split(' '));

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

line 61why, one step back
61 expect(program.opts().port).toBe('80');

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 62–66why, one step back
62 });
6364 test('when long flag followed by value then value is as specified', () => {65 const program = createPortProgram();66 program.parse('node test --port 80'.split(' '));

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

line 67why, one step back
67 expect(program.opts().port).toBe('80');

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 68–72why, one step back
68 });
6970 test('when long flag = value then value is as specified', () => {71 const program = createPortProgram();72 program.parse('node test --port=80'.split(' '));

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

line 73why, one step back
73 expect(program.opts().port).toBe('80');

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 74–80why, one step back
74 });
7576 test('when long flag followed empty string then value is empty string', () => {77 const program = createPortProgram();78 program79 .option('-c, --cheese [type]', 'optionally specify the type of cheese');80 program.parse(['node', 'test', '--cheese', '']);

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

line 81why, one step back
81 expect(program.opts().cheese).toBe('');

Merge branch 'master' into developJohn Geebefore adoption669190d

lines 82–83why, one step back
82 });
83});