forked from tj/commander.js
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.implies.test.js
67 lines (59 loc) · 2.42 KB
/
options.implies.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { Command, Option } = require('../');
describe('check priotities', () => {
test('when source undefined and implied undefined then implied is undefined', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }))
.option('--bar');
program.parse([], { from: 'user' });
expect(program.opts()).toEqual({});
});
test('when source default and implied undefined then implied is undefined', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }).default('default'))
.option('--bar');
program.parse([], { from: 'user' });
expect(program.opts()).toEqual({ foo: 'default' });
});
test('when source from env and implied undefined then implied is implied', () => {
const program = new Command();
const envName = 'COMMANDER_TEST_DELETE_ME';
process.env[envName] = 'env';
program
.addOption(new Option('--foo').implies({ bar: 'implied' }).env(envName))
.option('--bar');
program.parse([], { from: 'user' });
expect(program.opts()).toEqual({ foo: true, bar: 'implied' });
delete process.env[envName];
});
test('when source from cli and implied undefined then implied is implied', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }))
.option('--bar');
program.parse(['--foo'], { from: 'user' });
expect(program.opts()).toEqual({ foo: true, bar: 'implied' });
});
test('when source cli and implied default then implied is implied', () => {
const program = new Command();
program
.addOption(new Option('--foo').implies({ bar: 'implied' }))
.option('--bar', '', 'default');
program.parse(['--foo'], { from: 'user' });
expect(program.opts()).toEqual({ foo: true, bar: 'implied' });
});
test('when source cli and env default then implied is env', () => {
const program = new Command();
const envName = 'COMMANDER_TEST_DELETE_ME';
process.env[envName] = 'env';
program
.addOption(new Option('--foo').implies({ bar: 'implied' }))
.addOption(new Option('--bar <value>').env(envName));
program.parse(['--foo'], { from: 'user' });
expect(program.opts()).toEqual({ foo: true, bar: 'env' });
delete process.env[envName];
});
});
// Can store a value that is not actually an option (!)
// Can store more than one implied key