@@ -33,6 +33,7 @@ const {
3333 isAddressPrivate,
3434 fetchWithTimeout,
3535 setGlobalProxy,
36+ createSafeProxyAgent,
3637} = await import ( './fetch.js' ) ;
3738interface ErrorWithCode extends Error {
3839 code ?: string ;
@@ -55,6 +56,7 @@ describe('fetch utils', () => {
5556 return [ { address : '93.184.216.34' , family : 4 } ] ;
5657 } ) ;
5758 vi . unstubAllEnvs ( ) ;
59+ updateGlobalFetchTimeouts ( 60000 ) ;
5860 } ) ;
5961
6062 afterEach ( ( ) => {
@@ -239,17 +241,17 @@ describe('fetch utils', () => {
239241
240242 describe ( 'setGlobalProxy' , ( ) => {
241243 it ( 'should configure EnvHttpProxyAgent with experiment flag timeout and noProxy' , ( ) => {
242- const proxyUrl = 'http://proxy.example.com' ;
243- const noProxyValue = 'localhost,127.0.0.1' ;
244+ const proxyUrl = ' http://proxy.example.com ' ;
245+ const noProxyValue = ' localhost,127.0.0.1 ' ;
244246 vi . stubEnv ( 'NO_PROXY' , noProxyValue ) ;
245247
246248 updateGlobalFetchTimeouts ( 45773134 ) ;
247249 setGlobalProxy ( proxyUrl ) ;
248250
249251 expect ( EnvHttpProxyAgent ) . toHaveBeenCalledWith ( {
250- httpProxy : proxyUrl ,
251- httpsProxy : proxyUrl ,
252- noProxy : noProxyValue ,
252+ httpProxy : 'http://proxy.example.com' ,
253+ httpsProxy : 'http://proxy.example.com' ,
254+ noProxy : 'localhost,127.0.0.1' ,
253255 headersTimeout : 45773134 ,
254256 bodyTimeout : 300000 ,
255257 } ) ;
@@ -270,4 +272,22 @@ describe('fetch utils', () => {
270272 ) ;
271273 } ) ;
272274 } ) ;
275+
276+ describe ( 'createSafeProxyAgent' , ( ) => {
277+ it ( 'should create an EnvHttpProxyAgent with trimmed values and default timeouts' , ( ) => {
278+ const proxyUrl = ' http://proxy.example.com ' ;
279+ const noProxyValue = ' localhost,127.0.0.1 ' ;
280+ vi . stubEnv ( 'NO_PROXY' , noProxyValue ) ;
281+
282+ createSafeProxyAgent ( proxyUrl ) ;
283+
284+ expect ( EnvHttpProxyAgent ) . toHaveBeenCalledWith ( {
285+ httpProxy : 'http://proxy.example.com' ,
286+ httpsProxy : 'http://proxy.example.com' ,
287+ noProxy : 'localhost,127.0.0.1' ,
288+ headersTimeout : 60000 ,
289+ bodyTimeout : 300000 ,
290+ } ) ;
291+ } ) ;
292+ } ) ;
273293} ) ;
0 commit comments