@@ -10,6 +10,7 @@ const commander = require('../');
10
10
describe ( '.parse() args from' , ( ) => {
11
11
test ( 'when no args then use process.argv and app/script/args' , ( ) => {
12
12
const program = new commander . Command ( ) ;
13
+ program . argument ( '[args...]' ) ;
13
14
const hold = process . argv ;
14
15
process . argv = 'node script.js user' . split ( ' ' ) ;
15
16
program . parse ( ) ;
@@ -19,6 +20,7 @@ describe('.parse() args from', () => {
19
20
20
21
test ( 'when no args and electron properties and not default app then use process.argv and app/args' , ( ) => {
21
22
const program = new commander . Command ( ) ;
23
+ program . argument ( '[args...]' ) ;
22
24
const holdArgv = process . argv ;
23
25
process . versions . electron = '1.2.3' ;
24
26
process . argv = 'node user' . split ( ' ' ) ;
@@ -30,18 +32,21 @@ describe('.parse() args from', () => {
30
32
31
33
test ( 'when args then app/script/args' , ( ) => {
32
34
const program = new commander . Command ( ) ;
35
+ program . argument ( '[args...]' ) ;
33
36
program . parse ( 'node script.js user' . split ( ' ' ) ) ;
34
37
expect ( program . args ) . toEqual ( [ 'user' ] ) ;
35
38
} ) ;
36
39
37
40
test ( 'when args from "node" then app/script/args' , ( ) => {
38
41
const program = new commander . Command ( ) ;
42
+ program . argument ( '[args...]' ) ;
39
43
program . parse ( 'node script.js user' . split ( ' ' ) , { from : 'node' } ) ;
40
44
expect ( program . args ) . toEqual ( [ 'user' ] ) ;
41
45
} ) ;
42
46
43
47
test ( 'when args from "electron" and not default app then app/args' , ( ) => {
44
48
const program = new commander . Command ( ) ;
49
+ program . argument ( '[args...]' ) ;
45
50
const hold = process . defaultApp ;
46
51
process . defaultApp = undefined ;
47
52
program . parse ( 'customApp user' . split ( ' ' ) , { from : 'electron' } ) ;
@@ -51,6 +56,7 @@ describe('.parse() args from', () => {
51
56
52
57
test ( 'when args from "electron" and default app then app/script/args' , ( ) => {
53
58
const program = new commander . Command ( ) ;
59
+ program . argument ( '[args...]' ) ;
54
60
const hold = process . defaultApp ;
55
61
process . defaultApp = true ;
56
62
program . parse ( 'electron script user' . split ( ' ' ) , { from : 'electron' } ) ;
@@ -60,12 +66,14 @@ describe('.parse() args from', () => {
60
66
61
67
test ( 'when args from "user" then args' , ( ) => {
62
68
const program = new commander . Command ( ) ;
69
+ program . argument ( '[args...]' ) ;
63
70
program . parse ( 'user' . split ( ' ' ) , { from : 'user' } ) ;
64
71
expect ( program . args ) . toEqual ( [ 'user' ] ) ;
65
72
} ) ;
66
73
67
74
test ( 'when args from "silly" then throw' , ( ) => {
68
75
const program = new commander . Command ( ) ;
76
+ program . argument ( '[args...]' ) ;
69
77
expect ( ( ) => {
70
78
program . parse ( [ 'node' , 'script.js' ] , { from : 'silly' } ) ;
71
79
} ) . toThrow ( ) ;
@@ -75,6 +83,7 @@ describe('.parse() args from', () => {
75
83
'when node execArgv includes %s then app/args' ,
76
84
( flag ) => {
77
85
const program = new commander . Command ( ) ;
86
+ program . argument ( '[args...]' ) ;
78
87
const holdExecArgv = process . execArgv ;
79
88
const holdArgv = process . argv ;
80
89
process . argv = [ 'node' , 'user-arg' ] ;
@@ -91,6 +100,7 @@ describe('.parse() args from', () => {
91
100
describe ( 'return type' , ( ) => {
92
101
test ( 'when call .parse then returns program' , ( ) => {
93
102
const program = new commander . Command ( ) ;
103
+ program . argument ( '[args...]' ) ;
94
104
program . action ( ( ) => { } ) ;
95
105
96
106
const result = program . parse ( [ 'node' , 'test' ] ) ;
@@ -99,6 +109,7 @@ describe('return type', () => {
99
109
100
110
test ( 'when await .parseAsync then returns program' , async ( ) => {
101
111
const program = new commander . Command ( ) ;
112
+ program . argument ( '[args...]' ) ;
102
113
program . action ( ( ) => { } ) ;
103
114
104
115
const result = await program . parseAsync ( [ 'node' , 'test' ] ) ;
@@ -109,6 +120,7 @@ describe('return type', () => {
109
120
// Easy mistake to make when writing unit tests
110
121
test ( 'when parse strings instead of array then throw' , ( ) => {
111
122
const program = new commander . Command ( ) ;
123
+ program . argument ( '[args...]' ) ;
112
124
expect ( ( ) => {
113
125
program . parse ( 'node' , 'test' ) ;
114
126
} ) . toThrow ( ) ;
@@ -117,6 +129,7 @@ test('when parse strings instead of array then throw', () => {
117
129
describe ( 'parse parameter is treated as readonly, per TypeScript declaration' , ( ) => {
118
130
test ( 'when parse called then parameter does not change' , ( ) => {
119
131
const program = new commander . Command ( ) ;
132
+ program . argument ( '[args...]' ) ;
120
133
program . option ( '--debug' ) ;
121
134
const original = [ 'node' , '--debug' , 'arg' ] ;
122
135
const param = original . slice ( ) ;
@@ -126,6 +139,7 @@ describe('parse parameter is treated as readonly, per TypeScript declaration', (
126
139
127
140
test ( 'when parse called and parsed args later changed then parameter does not change' , ( ) => {
128
141
const program = new commander . Command ( ) ;
142
+ program . argument ( '[args...]' ) ;
129
143
program . option ( '--debug' ) ;
130
144
const original = [ 'node' , '--debug' , 'arg' ] ;
131
145
const param = original . slice ( ) ;
@@ -137,6 +151,7 @@ describe('parse parameter is treated as readonly, per TypeScript declaration', (
137
151
138
152
test ( 'when parse called and param later changed then parsed args do not change' , ( ) => {
139
153
const program = new commander . Command ( ) ;
154
+ program . argument ( '[args...]' ) ;
140
155
program . option ( '--debug' ) ;
141
156
const param = [ 'node' , '--debug' , 'arg' ] ;
142
157
program . parse ( param ) ;
@@ -151,6 +166,7 @@ describe('parse parameter is treated as readonly, per TypeScript declaration', (
151
166
describe ( 'parseAsync parameter is treated as readonly, per TypeScript declaration' , ( ) => {
152
167
test ( 'when parse called then parameter does not change' , async ( ) => {
153
168
const program = new commander . Command ( ) ;
169
+ program . argument ( '[args...]' ) ;
154
170
program . option ( '--debug' ) ;
155
171
const original = [ 'node' , '--debug' , 'arg' ] ;
156
172
const param = original . slice ( ) ;
@@ -160,6 +176,7 @@ describe('parseAsync parameter is treated as readonly, per TypeScript declaratio
160
176
161
177
test ( 'when parseAsync called and parsed args later changed then parameter does not change' , async ( ) => {
162
178
const program = new commander . Command ( ) ;
179
+ program . argument ( '[args...]' ) ;
163
180
program . option ( '--debug' ) ;
164
181
const original = [ 'node' , '--debug' , 'arg' ] ;
165
182
const param = original . slice ( ) ;
@@ -171,6 +188,7 @@ describe('parseAsync parameter is treated as readonly, per TypeScript declaratio
171
188
172
189
test ( 'when parseAsync called and param later changed then parsed args do not change' , async ( ) => {
173
190
const program = new commander . Command ( ) ;
191
+ program . argument ( '[args...]' ) ;
174
192
program . option ( '--debug' ) ;
175
193
const param = [ 'node' , '--debug' , 'arg' ] ;
176
194
await program . parseAsync ( param ) ;
0 commit comments