@@ -31,7 +31,8 @@ describe("parser", () => {
31
31
}
32
32
33
33
it ( "should parse nothing" , ( ) => {
34
- expect ( parse ( [ ] ) ) . toStrictEqual ( { _ : [ ] } ) } )
34
+ expect ( parse ( [ ] ) ) . toStrictEqual ( { _ : [ ] } )
35
+ } )
35
36
36
37
it ( "should parse all available options" , ( ) => {
37
38
expect (
@@ -71,32 +72,31 @@ describe("parser", () => {
71
72
"--" ,
72
73
"-5" ,
73
74
"--6" ,
74
- ] ) ) . toEqual (
75
- {
76
- _ : [ "1" , "2" , "3" , "4" , "-5" , "--6" ] ,
77
- auth : "none" ,
78
- "builtin-extensions-dir" : path . resolve ( "foobar" ) ,
79
- "cert-key" : path . resolve ( "qux" ) ,
80
- cert : {
81
- value : path . resolve ( "baz" ) ,
82
- } ,
83
- "extensions-dir" : path . resolve ( "foo" ) ,
84
- "extra-builtin-extensions-dir" : [ path . resolve ( "bazzle" ) ] ,
85
- "extra-extensions-dir" : [ path . resolve ( "nozzle" ) ] ,
86
- help : true ,
87
- home : "http://localhost:8080/" ,
88
- host : "0.0.0.0" ,
89
- json : true ,
90
- log : "error" ,
91
- open : true ,
92
- port : 8081 ,
93
- socket : path . resolve ( "mumble" ) ,
94
- "user-data-dir" : path . resolve ( "bar" ) ,
95
- verbose : true ,
96
- version : true ,
97
- "bind-addr" : "192.169.0.1:8080" ,
75
+ ] ) ,
76
+ ) . toEqual ( {
77
+ _ : [ "1" , "2" , "3" , "4" , "-5" , "--6" ] ,
78
+ auth : "none" ,
79
+ "builtin-extensions-dir" : path . resolve ( "foobar" ) ,
80
+ "cert-key" : path . resolve ( "qux" ) ,
81
+ cert : {
82
+ value : path . resolve ( "baz" ) ,
98
83
} ,
99
- )
84
+ "extensions-dir" : path . resolve ( "foo" ) ,
85
+ "extra-builtin-extensions-dir" : [ path . resolve ( "bazzle" ) ] ,
86
+ "extra-extensions-dir" : [ path . resolve ( "nozzle" ) ] ,
87
+ help : true ,
88
+ home : "http://localhost:8080/" ,
89
+ host : "0.0.0.0" ,
90
+ json : true ,
91
+ log : "error" ,
92
+ open : true ,
93
+ port : 8081 ,
94
+ socket : path . resolve ( "mumble" ) ,
95
+ "user-data-dir" : path . resolve ( "bar" ) ,
96
+ verbose : true ,
97
+ version : true ,
98
+ "bind-addr" : "192.169.0.1:8080" ,
99
+ } )
100
100
} )
101
101
102
102
it ( "should work with short options" , ( ) => {
@@ -124,7 +124,7 @@ describe("parser", () => {
124
124
125
125
process . env . LOG_LEVEL = "trace"
126
126
const updated = await setDefaults ( args )
127
- expect ( updated ) . toStrictEqual ( {
127
+ expect ( updated ) . toStrictEqual ( {
128
128
...updated ,
129
129
_ : [ ] ,
130
130
log : "trace" ,
@@ -142,7 +142,7 @@ describe("parser", () => {
142
142
} )
143
143
144
144
process . env . LOG_LEVEL = "debug"
145
- const defaults = await setDefaults ( args )
145
+ const defaults = await setDefaults ( args )
146
146
expect ( defaults ) . toEqual ( {
147
147
...defaults ,
148
148
_ : [ ] ,
@@ -154,7 +154,7 @@ describe("parser", () => {
154
154
155
155
process . env . LOG_LEVEL = "trace"
156
156
const updated = await setDefaults ( args )
157
- expect ( updated ) . toEqual ( {
157
+ expect ( updated ) . toEqual ( {
158
158
...defaults ,
159
159
_ : [ ] ,
160
160
log : "info" ,
@@ -172,7 +172,7 @@ describe("parser", () => {
172
172
173
173
process . env . LOG_LEVEL = "warn"
174
174
const updatedAgain = await setDefaults ( args )
175
- expect ( updatedAgain ) . toEqual ( {
175
+ expect ( updatedAgain ) . toEqual ( {
176
176
...defaults ,
177
177
_ : [ ] ,
178
178
log : "trace" ,
@@ -206,7 +206,7 @@ describe("parser", () => {
206
206
} )
207
207
208
208
it ( "should error if the option doesn't exist" , ( ) => {
209
- expect ( ( ) => parse ( [ "--foo" ] ) ) . toThrowError ( / U n k n o w n o p t i o n - - f o o / )
209
+ expect ( ( ) => parse ( [ "--foo" ] ) ) . toThrowError ( / U n k n o w n o p t i o n - - f o o / )
210
210
} )
211
211
212
212
it ( "should not error if the value is optional" , ( ) => {
@@ -246,28 +246,25 @@ describe("parser", () => {
246
246
} )
247
247
} )
248
248
249
- it (
250
- "should enforce cert-key with cert value or otherwise generate one" ,
251
- async ( ) => {
252
- const args = parse ( [ "--cert" ] )
253
- expect ( args ) . toEqual ( {
254
- _ : [ ] ,
255
- cert : {
256
- value : undefined ,
257
- } ,
258
- } )
259
- expect ( ( ) => parse ( [ "--cert" , "test" ] ) ) . toThrowError ( / - - c e r t - k e y i s m i s s i n g / )
260
- const defaultArgs = await setDefaults ( args )
261
- expect ( defaultArgs ) . toEqual ( {
262
- _ : [ ] ,
263
- ...defaults ,
264
- cert : {
265
- value : path . join ( paths . data , "localhost.crt" ) ,
266
- } ,
267
- "cert-key" : path . join ( paths . data , "localhost.key" ) ,
268
- } )
269
- }
270
- )
249
+ it ( "should enforce cert-key with cert value or otherwise generate one" , async ( ) => {
250
+ const args = parse ( [ "--cert" ] )
251
+ expect ( args ) . toEqual ( {
252
+ _ : [ ] ,
253
+ cert : {
254
+ value : undefined ,
255
+ } ,
256
+ } )
257
+ expect ( ( ) => parse ( [ "--cert" , "test" ] ) ) . toThrowError ( / - - c e r t - k e y i s m i s s i n g / )
258
+ const defaultArgs = await setDefaults ( args )
259
+ expect ( defaultArgs ) . toEqual ( {
260
+ _ : [ ] ,
261
+ ...defaults ,
262
+ cert : {
263
+ value : path . join ( paths . data , "localhost.crt" ) ,
264
+ } ,
265
+ "cert-key" : path . join ( paths . data , "localhost.key" ) ,
266
+ } )
267
+ } )
271
268
272
269
it ( "should override with --link" , async ( ) => {
273
270
const args = parse ( "--cert test --cert-key test --socket test --host 0.0.0.0 --port 8888 --link test" . split ( " " ) )
@@ -310,7 +307,7 @@ describe("parser", () => {
310
307
_ : [ ] ,
311
308
} )
312
309
313
- const defaultArgs = await setDefaults ( args )
310
+ const defaultArgs = await setDefaults ( args )
314
311
expect ( defaultArgs ) . toEqual ( {
315
312
...defaults ,
316
313
_ : [ ] ,
@@ -352,11 +349,11 @@ describe("cli", () => {
352
349
} )
353
350
354
351
it ( "should use existing if inside code-server" , async ( ) => {
355
- process . env . VSCODE_IPC_HOOK_CLI = "test"
352
+ process . env . VSCODE_IPC_HOOK_CLI = "test"
356
353
expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( "test" )
357
354
358
355
args . port = 8081
359
- args . _ . push ( "./file" )
356
+ args . _ . push ( "./file" )
360
357
expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( "test" )
361
358
} )
362
359
@@ -370,7 +367,7 @@ describe("cli", () => {
370
367
args . port = 8081
371
368
await expect ( shouldOpenInExistingInstance ( args ) ) . resolves . toStrictEqual ( "test" )
372
369
} )
373
-
370
+
374
371
it ( "should use existing if --new-window is set" , async ( ) => {
375
372
args [ "new-window" ] = true
376
373
expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
@@ -382,31 +379,28 @@ describe("cli", () => {
382
379
expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( "test" )
383
380
} )
384
381
385
- it (
386
- "should use existing if no unrelated flags are set, has positional, and socket is active" ,
387
- async ( ) => {
388
- expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
389
-
390
- args . _ . push ( "./file" )
391
- expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
392
-
393
- const socketPath = path . join ( testDir , "socket" )
394
- await fs . writeFile ( vscodeIpcPath , socketPath )
395
- expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
396
-
397
- await new Promise ( ( resolve ) => {
398
- const server = net . createServer ( ( ) => {
399
- // Close after getting the first connection.
400
- server . close ( )
401
- } )
402
- server . once ( "listening" , ( ) => resolve ( server ) )
403
- server . listen ( socketPath )
382
+ it ( "should use existing if no unrelated flags are set, has positional, and socket is active" , async ( ) => {
383
+ expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
384
+
385
+ args . _ . push ( "./file" )
386
+ expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
387
+
388
+ const socketPath = path . join ( testDir , "socket" )
389
+ await fs . writeFile ( vscodeIpcPath , socketPath )
390
+ expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
391
+
392
+ await new Promise ( ( resolve ) => {
393
+ const server = net . createServer ( ( ) => {
394
+ // Close after getting the first connection.
395
+ server . close ( )
404
396
} )
397
+ server . once ( "listening" , ( ) => resolve ( server ) )
398
+ server . listen ( socketPath )
399
+ } )
405
400
406
- expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( socketPath )
401
+ expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( socketPath )
407
402
408
- args . port = 8081
409
- expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
410
- }
411
- )
403
+ args . port = 8081
404
+ expect ( await shouldOpenInExistingInstance ( args ) ) . toStrictEqual ( undefined )
405
+ } )
412
406
} )
0 commit comments