|
1 |
| -const assert = require('assert'); |
2 |
| -const cli = require('../lib'); |
| 1 | +import { deepEqual, notStrictEqual, strictEqual, throws, deepStrictEqual, doesNotThrow } from 'assert'; |
| 2 | +import * as clap from 'clap'; |
3 | 3 |
|
4 |
| -describe('one arg options', function() { |
5 |
| - describe('required param', function() { |
6 |
| - it('should not be in values by default', function() { |
7 |
| - const command = cli.command() |
| 4 | +describe('one arg options', () => { |
| 5 | + describe('required param', () => { |
| 6 | + it('should not be in values by default', () => { |
| 7 | + const command = clap.command() |
8 | 8 | .option('--option <arg>');
|
9 | 9 |
|
10 | 10 | const { options } = command.run([]);
|
11 |
| - assert.deepEqual(options, Object.create(null)); |
12 |
| - assert.notStrictEqual(command.getOption('option'), null); |
| 11 | + deepEqual(options, Object.create(null)); |
| 12 | + notStrictEqual(command.getOption('option'), null); |
13 | 13 | });
|
14 | 14 |
|
15 |
| - it('should store default value', function() { |
16 |
| - const command = cli.command() |
| 15 | + it('should store default value', () => { |
| 16 | + const command = clap.command() |
17 | 17 | .option('--option <arg>', 'description', 123);
|
18 | 18 |
|
19 | 19 | const { options } = command.run([]);
|
20 |
| - assert.strictEqual(options.option, 123); |
| 20 | + strictEqual(options.option, 123); |
21 | 21 | });
|
22 | 22 |
|
23 |
| - it('default value should be wrapped by normalize function', function() { |
24 |
| - const command = cli.command() |
| 23 | + it('default value should be wrapped by normalize function', () => { |
| 24 | + const command = clap.command() |
25 | 25 | .option('--option <arg>', 'description', value => value * 2, 123);
|
26 | 26 |
|
27 | 27 | const { options } = command.run([]);
|
28 |
| - assert.strictEqual(options.option, 246); |
| 28 | + strictEqual(options.option, 246); |
29 | 29 | });
|
30 | 30 |
|
31 |
| - it('should not be in values when normalize function preset but no default value', function() { |
32 |
| - const command = cli.command() |
33 |
| - .option('--option <arg>', 'description', function() { |
| 31 | + it('should not be in values when normalize function preset but no default value', () => { |
| 32 | + const command = clap.command() |
| 33 | + .option('--option <arg>', 'description', () => { |
34 | 34 | return 123;
|
35 | 35 | });
|
36 | 36 |
|
37 | 37 | const { options } = command.run([]);
|
38 |
| - assert.deepEqual(options, Object.create(null)); |
| 38 | + deepEqual(options, Object.create(null)); |
39 | 39 | });
|
40 | 40 |
|
41 |
| - it('should read only one argument', function() { |
| 41 | + it('should read only one argument', () => { |
42 | 42 | let ok = false;
|
43 | 43 | let values;
|
44 | 44 |
|
45 |
| - const command = cli.command() |
| 45 | + const command = clap.command() |
46 | 46 | .option('--option <arg>', 'description')
|
47 | 47 | .finishContext(({ options }) => values = options)
|
48 | 48 | .command('test')
|
49 | 49 | .action(() => ok = true)
|
50 | 50 | .end();
|
51 | 51 |
|
52 | 52 | command.run(['--option', '1', 'test']);
|
53 |
| - assert.strictEqual(values.option, '1'); |
54 |
| - assert.strictEqual(ok, true); |
| 53 | + strictEqual(values.option, '1'); |
| 54 | + strictEqual(ok, true); |
55 | 55 | });
|
56 | 56 |
|
57 |
| - it('should ignore commands', function() { |
| 57 | + it('should ignore commands', () => { |
58 | 58 | let ok = true;
|
59 |
| - const command = cli.command() |
| 59 | + const command = clap.command() |
60 | 60 | .option('--option <arg>', 'description')
|
61 | 61 | .command('test')
|
62 | 62 | .action(() => ok = false)
|
63 | 63 | .end();
|
64 | 64 |
|
65 | 65 | const { options } = command.run(['--option', 'test']);
|
66 |
| - assert.strictEqual(ok, true); |
67 |
| - assert.strictEqual(options.option, 'test'); |
| 66 | + strictEqual(ok, true); |
| 67 | + strictEqual(options.option, 'test'); |
68 | 68 | });
|
69 | 69 |
|
70 |
| - it('should be exception if arg is not specified (no more arguments)', function() { |
71 |
| - const command = cli.command() |
| 70 | + it('should be exception if arg is not specified (no more arguments)', () => { |
| 71 | + const command = clap.command() |
72 | 72 | .option('--option <arg>', 'description');
|
73 | 73 |
|
74 |
| - assert.throws( |
| 74 | + throws( |
75 | 75 | () => command.run(['--option']),
|
76 | 76 | /Option --option should be used with at least 1 argument\(s\)/
|
77 | 77 | );
|
78 | 78 | });
|
79 | 79 |
|
80 |
| - it('should be exception if arg is not specified (another option next)', function() { |
81 |
| - const command = cli.command() |
| 80 | + it('should be exception if arg is not specified (another option next)', () => { |
| 81 | + const command = clap.command() |
82 | 82 | .option('--test')
|
83 | 83 | .option('--option <arg>', 'description');
|
84 | 84 |
|
85 |
| - assert.throws( |
| 85 | + throws( |
86 | 86 | () => command.run(['--option', '--test']),
|
87 | 87 | /Option --option should be used with at least 1 argument\(s\)/
|
88 | 88 | );
|
89 | 89 | });
|
90 | 90 |
|
91 |
| - it('#setValue should normalizenew value', function() { |
92 |
| - const command = cli.command() |
| 91 | + it('#setValue should normalizenew value', () => { |
| 92 | + const command = clap.command() |
93 | 93 | .option('--option <arg>', 'description', value => value * 2);
|
94 | 94 |
|
95 | 95 | const { options } = command.run([]);
|
96 | 96 | options.option = 123;
|
97 |
| - assert.strictEqual(options.option, 246); |
| 97 | + strictEqual(options.option, 246); |
98 | 98 | });
|
99 | 99 | });
|
100 | 100 |
|
101 |
| - describe('optional param', function() { |
102 |
| - it('should not be in values by default', function() { |
103 |
| - const command = cli.command() |
| 101 | + describe('optional param', () => { |
| 102 | + it('should not be in values by default', () => { |
| 103 | + const command = clap.command() |
104 | 104 | .option('--option [arg]');
|
105 | 105 |
|
106 | 106 | const { options } = command.run([]);
|
107 |
| - assert.deepEqual(options, Object.create(null)); |
108 |
| - assert.notStrictEqual(command.getOption('option'), null); |
| 107 | + deepEqual(options, Object.create(null)); |
| 108 | + notStrictEqual(command.getOption('option'), null); |
109 | 109 | });
|
110 | 110 |
|
111 |
| - it('should store default value', function() { |
112 |
| - const command = cli.command() |
| 111 | + it('should store default value', () => { |
| 112 | + const command = clap.command() |
113 | 113 | .option('--option [arg]', 'description', 123);
|
114 | 114 |
|
115 | 115 | const actual = command.run([]);
|
116 |
| - assert.strictEqual(actual.options.option, 123); |
| 116 | + strictEqual(actual.options.option, 123); |
117 | 117 | });
|
118 | 118 |
|
119 |
| - it('default value should be wrapped by normalize function', function() { |
120 |
| - const command = cli.command() |
| 119 | + it('default value should be wrapped by normalize function', () => { |
| 120 | + const command = clap.command() |
121 | 121 | .option('--option [arg]', 'description', function(value) {
|
122 | 122 | return value * 2;
|
123 | 123 | }, 123);
|
124 | 124 |
|
125 | 125 | const actual = command.run([]);
|
126 |
| - assert.strictEqual(actual.options.option, 246); |
| 126 | + strictEqual(actual.options.option, 246); |
127 | 127 | });
|
128 | 128 |
|
129 |
| - it('should not be in values when normalize function preset but no default value', function() { |
130 |
| - const command = cli.command() |
131 |
| - .option('--option [arg]', 'description', function() { |
| 129 | + it('should not be in values when normalize function preset but no default value', () => { |
| 130 | + const command = clap.command() |
| 131 | + .option('--option [arg]', 'description', () => { |
132 | 132 | return 123;
|
133 | 133 | });
|
134 | 134 |
|
135 | 135 | const actual = command.run([]);
|
136 |
| - assert.deepStrictEqual(actual.options, Object.create(null)); |
| 136 | + deepStrictEqual(actual.options, Object.create(null)); |
137 | 137 | });
|
138 | 138 |
|
139 |
| - it('should read only one argument', function() { |
| 139 | + it('should read only one argument', () => { |
140 | 140 | let ok = false;
|
141 | 141 | let values;
|
142 | 142 |
|
143 |
| - const command = cli.command() |
| 143 | + const command = clap.command() |
144 | 144 | .option('--option [arg]', 'description')
|
145 | 145 | .finishContext(({ options }) => values = options)
|
146 | 146 | .command('test')
|
147 | 147 | .action(() => ok = true)
|
148 | 148 | .end();
|
149 | 149 |
|
150 | 150 | command.run(['--option', '1', 'test']);
|
151 |
| - assert.strictEqual(ok, true); |
152 |
| - assert.strictEqual(values.option, '1'); |
| 151 | + strictEqual(ok, true); |
| 152 | + strictEqual(values.option, '1'); |
153 | 153 | });
|
154 | 154 |
|
155 |
| - it('should ignore commands', function() { |
| 155 | + it('should ignore commands', () => { |
156 | 156 | let ok = true;
|
157 | 157 |
|
158 |
| - const command = cli.command() |
| 158 | + const command = clap.command() |
159 | 159 | .option('--option [arg]', 'description')
|
160 | 160 | .command('test')
|
161 | 161 | .action(() => ok = false)
|
162 | 162 | .end();
|
163 | 163 |
|
164 | 164 | const { options } = command.run(['--option', 'test']);
|
165 |
| - assert.strictEqual(ok, true); |
166 |
| - assert.strictEqual(options.option, 'test'); |
| 165 | + strictEqual(ok, true); |
| 166 | + strictEqual(options.option, 'test'); |
167 | 167 | });
|
168 | 168 |
|
169 |
| - it('should not be exception if arg is not specified (no more arguments)', function() { |
170 |
| - const command = cli.command() |
| 169 | + it('should not be exception if arg is not specified (no more arguments)', () => { |
| 170 | + const command = clap.command() |
171 | 171 | .option('--option [arg]', 'description');
|
172 | 172 |
|
173 |
| - assert.doesNotThrow(function() { |
| 173 | + doesNotThrow(() => { |
174 | 174 | command.run(['--option']);
|
175 | 175 | });
|
176 | 176 | });
|
177 | 177 |
|
178 |
| - it('should not be exception if arg is not specified (another option next)', function() { |
179 |
| - const command = cli.command() |
| 178 | + it('should not be exception if arg is not specified (another option next)', () => { |
| 179 | + const command = clap.command() |
180 | 180 | .option('--test')
|
181 | 181 | .option('--option [arg]', 'description');
|
182 | 182 |
|
183 |
| - assert.doesNotThrow(function() { |
| 183 | + doesNotThrow(() => { |
184 | 184 | command.run(['--option', '--test']);
|
185 | 185 | });
|
186 | 186 | });
|
187 | 187 |
|
188 |
| - it('set value to options should normalize new value', function() { |
189 |
| - const command = cli.command() |
| 188 | + it('set value to options should normalize new value', () => { |
| 189 | + const command = clap.command() |
190 | 190 | .option('--option [arg]', 'description', value => value * 2);
|
191 | 191 |
|
192 | 192 | const { options } = command.run([]);
|
193 | 193 | options.option = 123;
|
194 |
| - assert.strictEqual(options.option, 246); |
| 194 | + strictEqual(options.option, 246); |
195 | 195 | });
|
196 | 196 | });
|
197 | 197 | });
|
0 commit comments