@@ -19,11 +19,7 @@ jest.mock('@sentry/core', () => {
1919 } ;
2020} ) ;
2121
22- // eslint-disable-next-line @typescript-eslint/no-var-requires
23- const httpProxyAgent = require ( 'https-proxy-agent' ) ;
24- jest . mock ( 'https-proxy-agent' , ( ) => {
25- return jest . fn ( ) . mockImplementation ( ( ) => new http . Agent ( { keepAlive : false , maxSockets : 30 , timeout : 2000 } ) ) ;
26- } ) ;
22+ import * as httpProxyAgent from 'https-proxy-agent' ;
2723
2824const SUCCESS = 200 ;
2925const RATE_LIMIT = 429 ;
@@ -185,6 +181,11 @@ describe('makeNewHttpsTransport()', () => {
185181 } ) ;
186182
187183 describe ( 'proxy' , ( ) => {
184+ const proxyAgentSpy = jest
185+ . spyOn ( httpProxyAgent , 'HttpsProxyAgent' )
186+ // @ts -ignore
187+ . mockImplementation ( ( ) => new http . Agent ( { keepAlive : false , maxSockets : 30 , timeout : 2000 } ) ) ;
188+
188189 it ( 'can be configured through option' , ( ) => {
189190 makeNodeTransport ( {
190191 ...defaultOptions ,
@@ -193,8 +194,8 @@ describe('makeNewHttpsTransport()', () => {
193194 proxy : 'https://example.com' ,
194195 } ) ;
195196
196- expect ( httpProxyAgent ) . toHaveBeenCalledTimes ( 1 ) ;
197- expect ( httpProxyAgent ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
197+ expect ( proxyAgentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
198+ expect ( proxyAgentSpy ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
198199 } ) ;
199200
200201 it ( 'can be configured through env variables option (http)' , ( ) => {
@@ -205,8 +206,8 @@ describe('makeNewHttpsTransport()', () => {
205206 url : 'https://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622' ,
206207 } ) ;
207208
208- expect ( httpProxyAgent ) . toHaveBeenCalledTimes ( 1 ) ;
209- expect ( httpProxyAgent ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
209+ expect ( proxyAgentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
210+ expect ( proxyAgentSpy ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
210211 delete process . env . http_proxy ;
211212 } ) ;
212213
@@ -218,8 +219,8 @@ describe('makeNewHttpsTransport()', () => {
218219 url : 'https://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622' ,
219220 } ) ;
220221
221- expect ( httpProxyAgent ) . toHaveBeenCalledTimes ( 1 ) ;
222- expect ( httpProxyAgent ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
222+ expect ( proxyAgentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
223+ expect ( proxyAgentSpy ) . toHaveBeenCalledWith ( 'https://example.com' ) ;
223224 delete process . env . https_proxy ;
224225 } ) ;
225226
@@ -232,8 +233,8 @@ describe('makeNewHttpsTransport()', () => {
232233 proxy : 'https://bar.com' ,
233234 } ) ;
234235
235- expect ( httpProxyAgent ) . toHaveBeenCalledTimes ( 1 ) ;
236- expect ( httpProxyAgent ) . toHaveBeenCalledWith ( 'https://bar.com' ) ;
236+ expect ( proxyAgentSpy ) . toHaveBeenCalledTimes ( 1 ) ;
237+ expect ( proxyAgentSpy ) . toHaveBeenCalledWith ( 'https://bar.com' ) ;
237238 delete process . env . https_proxy ;
238239 } ) ;
239240
@@ -246,7 +247,7 @@ describe('makeNewHttpsTransport()', () => {
246247 proxy : 'https://example.com' ,
247248 } ) ;
248249
249- expect ( httpProxyAgent ) . not . toHaveBeenCalled ( ) ;
250+ expect ( proxyAgentSpy ) . not . toHaveBeenCalled ( ) ;
250251
251252 delete process . env . no_proxy ;
252253 } ) ;
@@ -261,7 +262,7 @@ describe('makeNewHttpsTransport()', () => {
261262 url : 'https://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622' ,
262263 } ) ;
263264
264- expect ( httpProxyAgent ) . not . toHaveBeenCalled ( ) ;
265+ expect ( proxyAgentSpy ) . not . toHaveBeenCalled ( ) ;
265266
266267 delete process . env . no_proxy ;
267268 delete process . env . http_proxy ;
@@ -277,7 +278,7 @@ describe('makeNewHttpsTransport()', () => {
277278 url : 'https://9e9fd4523d784609a5fc0ebb1080592f@sentry.io:8989/mysubpath/50622' ,
278279 } ) ;
279280
280- expect ( httpProxyAgent ) . not . toHaveBeenCalled ( ) ;
281+ expect ( proxyAgentSpy ) . not . toHaveBeenCalled ( ) ;
281282
282283 delete process . env . no_proxy ;
283284 delete process . env . http_proxy ;
0 commit comments