@@ -166,8 +166,9 @@ describe('proxy options handling', function () {
166
166
let runJS : ( js : string ) => Promise < any > ;
167
167
let testResolveProxy : (
168
168
proxyOptions : DevtoolsProxyOptions ,
169
- url : string
170
- ) => Promise < string > ;
169
+ url : string ,
170
+ expectation : string
171
+ ) => Promise < void > ;
171
172
let setup : HTTPServerProxyTestSetup ;
172
173
173
174
before ( async function ( ) {
@@ -219,14 +220,16 @@ describe('proxy options handling', function () {
219
220
return JSON . parse ( response ) ;
220
221
} ;
221
222
222
- testResolveProxy = async ( proxyOptions , url ) => {
223
+ testResolveProxy = async ( proxyOptions , url , expectation ) => {
224
+ const config = translateToElectronProxyConfig ( proxyOptions ) ;
223
225
// https://www.electronjs.org/docs/latest/api/app#appsetproxyconfig
224
226
// https://www.electronjs.org/docs/latest/api/app#appresolveproxyurl
225
- return await runJS ( `app.setProxy(${ JSON . stringify (
226
- translateToElectronProxyConfig ( proxyOptions )
227
+ const actual = await runJS ( `app.setProxy(${ JSON . stringify (
228
+ config
227
229
) } ).then(_ => {
228
230
return app.resolveProxy(${ JSON . stringify ( url ) } );
229
231
})` ) ;
232
+ expect ( { actual, config } ) . to . have . property ( 'actual' , expectation ) ;
230
233
} ;
231
234
} ) ;
232
235
@@ -243,68 +246,73 @@ describe('proxy options handling', function () {
243
246
} ) ;
244
247
245
248
it ( 'correctly handles explicit proxies' , async function ( ) {
246
- expect (
247
- await testResolveProxy (
248
- {
249
- proxy : 'http://example.com:12345' ,
250
- } ,
251
- 'http://example.net'
252
- )
253
- ) . to . equal ( 'PROXY example.com:12345' ) ;
254
- expect (
255
- await testResolveProxy (
256
- {
257
- proxy : 'http://example.com:12345' ,
258
- noProxyHosts : 'localhost' ,
259
- } ,
260
- 'http://example.net'
261
- )
262
- ) . to . equal ( 'PROXY example.com:12345' ) ;
263
- expect (
264
- await testResolveProxy (
265
- {
266
- proxy : 'http://example.com:12345' ,
267
- noProxyHosts : 'localhost' ,
268
- } ,
269
- 'http://localhost'
270
- )
271
- ) . to . equal ( 'DIRECT' ) ;
272
- expect (
273
- await testResolveProxy (
274
- {
275
- proxy : 'http://example.com:12345' ,
276
- noProxyHosts : 'localhost' ,
277
- } ,
278
- 'http://localhost:1234'
279
- )
280
- ) . to . equal ( 'DIRECT' ) ;
281
- expect (
282
- await testResolveProxy (
283
- {
284
- proxy : 'socks5://example.com:12345' ,
285
- } ,
286
- 'http://example.net'
287
- )
288
- ) . to . equal ( 'SOCKS5 example.com:12345' ) ;
249
+ await testResolveProxy (
250
+ {
251
+ proxy : 'http://example.com:12345' ,
252
+ } ,
253
+ 'http://example.net' ,
254
+
255
+ 'PROXY example.com:12345'
256
+ ) ;
257
+
258
+ await testResolveProxy (
259
+ {
260
+ proxy : 'http://example.com:12345' ,
261
+ noProxyHosts : 'localhost' ,
262
+ } ,
263
+ 'http://example.net' ,
264
+
265
+ 'PROXY example.com:12345'
266
+ ) ;
267
+
268
+ await testResolveProxy (
269
+ {
270
+ proxy : 'http://example.com:12345' ,
271
+ noProxyHosts : 'localhost' ,
272
+ } ,
273
+ 'http://localhost' ,
274
+
275
+ 'DIRECT'
276
+ ) ;
277
+
278
+ await testResolveProxy (
279
+ {
280
+ proxy : 'http://example.com:12345' ,
281
+ noProxyHosts : 'localhost' ,
282
+ } ,
283
+ 'http://localhost:1234' ,
284
+
285
+ 'DIRECT'
286
+ ) ;
287
+
288
+ await testResolveProxy (
289
+ {
290
+ proxy : 'socks5://example.com:12345' ,
291
+ } ,
292
+ 'http://example.net' ,
293
+
294
+ 'SOCKS5 example.com:12345'
295
+ ) ;
289
296
} ) ;
290
297
291
298
it ( 'correctly handles pac-script-specified proxies' , async function ( ) {
292
- expect (
293
- await testResolveProxy (
294
- {
295
- proxy : `pac+http://127.0.0.1:${ setup . httpServerPort } /pac` ,
296
- } ,
297
- 'http://example.com'
298
- )
299
- ) . to . equal ( `SOCKS5 127.0.0.1:${ setup . socks5ProxyPort } ` ) ;
300
- expect (
301
- await testResolveProxy (
302
- {
303
- proxy : `pac+http://127.0.0.1:${ setup . httpServerPort } /pac` ,
304
- } ,
305
- 'http://pac-invalidproxy/test'
306
- )
307
- ) . to . equal ( `SOCKS5 127.0.0.1:1` ) ;
299
+ await testResolveProxy (
300
+ {
301
+ proxy : `pac+http://127.0.0.1:${ setup . httpServerPort } /pac` ,
302
+ } ,
303
+ 'http://example.com' ,
304
+
305
+ `SOCKS5 127.0.0.1:${ setup . socks5ProxyPort } `
306
+ ) ;
307
+
308
+ await testResolveProxy (
309
+ {
310
+ proxy : `pac+http://127.0.0.1:${ setup . httpServerPort } /pac` ,
311
+ } ,
312
+ 'http://pac-invalidproxy/test' ,
313
+
314
+ `SOCKS5 127.0.0.1:1`
315
+ ) ;
308
316
} ) ;
309
317
310
318
it ( 'correctly handles environment-specified proxies' , async function ( ) {
@@ -317,39 +325,40 @@ describe('proxy options handling', function () {
317
325
noProxyHosts : 'example.net:4567' ,
318
326
useEnvironmentVariableProxies : true ,
319
327
} ;
320
- expect ( await testResolveProxy ( config , 'http://localhost' ) ) . to . equal (
321
- 'DIRECT'
322
- ) ;
323
- expect ( await testResolveProxy ( config , 'http://example.net' ) ) . to . equal (
328
+ await testResolveProxy ( config , 'http://localhost' , 'DIRECT' ) ;
329
+ await testResolveProxy (
330
+ config ,
331
+ 'http://example.net' ,
324
332
'HTTPS http-proxy.example.net:443'
325
333
) ;
326
- expect ( await testResolveProxy ( config , 'https://example.net' ) ) . to . equal (
334
+ await testResolveProxy (
335
+ config ,
336
+ 'https://example.net' ,
327
337
'PROXY https-proxy.example.net:80'
328
338
) ;
329
- expect (
330
- await testResolveProxy ( config , 'https://example.net:1234' )
331
- ) . to . equal ( 'DIRECT' ) ;
332
- expect (
333
- await testResolveProxy ( config , 'https://example.net:4567' )
334
- ) . to . equal ( 'DIRECT' ) ;
335
- expect (
336
- await testResolveProxy ( config , 'https://example.net:9801' )
337
- ) . to . equal ( 'PROXY https-proxy.example.net:80' ) ;
338
- expect ( await testResolveProxy ( config , 'https://example.com' ) ) . to . equal (
339
- 'DIRECT'
339
+
340
+ await testResolveProxy ( config , 'https://example.net:1234' , 'DIRECT' ) ;
341
+
342
+ await testResolveProxy ( config , 'https://example.net:4567' , 'DIRECT' ) ;
343
+
344
+ await testResolveProxy (
345
+ config ,
346
+ 'https://example.net:9801' ,
347
+ 'PROXY https-proxy.example.net:80'
340
348
) ;
341
- expect (
342
- await testResolveProxy (
343
- {
344
- ...config ,
345
- env : {
346
- ...config . env ,
347
- ALL_PROXY : 'http://fallback.example.com:1' ,
348
- } ,
349
+ await testResolveProxy ( config , 'https://example.com' , 'DIRECT' ) ;
350
+ await testResolveProxy (
351
+ {
352
+ ...config ,
353
+ env : {
354
+ ...config . env ,
355
+ ALL_PROXY : 'http://fallback.example.com:1' ,
349
356
} ,
350
- 'ftp://mongodb.net'
351
- )
352
- ) . to . equal ( 'PROXY fallback.example.com:1' ) ;
357
+ } ,
358
+ 'ftp://mongodb.net' ,
359
+
360
+ 'PROXY fallback.example.com:1'
361
+ ) ;
353
362
} ) ;
354
363
} ) ;
355
364
} ) ;
0 commit comments