|
1 | 1 | import AbortController from 'abort-controller'; |
2 | | -import fetchWithTimeout from '../utils/fetch-with-timeout.js'; |
3 | | -import { getProxyAgent } from '@redocly/openapi-core'; |
4 | 2 | import { HttpsProxyAgent } from 'https-proxy-agent'; |
| 3 | +import fetchWithTimeout from '../utils/fetch-with-timeout.js'; |
| 4 | +import * as proxyAgent from '../utils/proxy-agent.js'; |
5 | 5 |
|
6 | 6 | const signalInstance = new AbortController().signal; |
7 | 7 |
|
@@ -31,6 +31,11 @@ const mockFetch = vi.fn(() => |
31 | 31 | const originalFetch = global.fetch; |
32 | 32 | global.fetch = mockFetch; |
33 | 33 |
|
| 34 | +vi.mock('../utils/get-proxy-agent.js', async () => { |
| 35 | + const actual = await vi.importActual('../utils/get-proxy-agent.js'); |
| 36 | + return { ...actual }; |
| 37 | +}); |
| 38 | + |
34 | 39 | describe('fetchWithTimeout', () => { |
35 | 40 | beforeAll(() => { |
36 | 41 | global.setTimeout = vi.fn() as any; |
@@ -60,12 +65,12 @@ describe('fetchWithTimeout', () => { |
60 | 65 | }); |
61 | 66 |
|
62 | 67 | it('should call fetch with proxy agent', async () => { |
63 | | - const proxyAgent = new HttpsProxyAgent('http://localhost'); |
64 | | - vi.mocked(getProxyAgent).mockReturnValueOnce(proxyAgent as any); |
| 68 | + const dispatcher = new HttpsProxyAgent('http://localhost'); |
| 69 | + vi.spyOn(proxyAgent, 'getProxyAgent').mockReturnValueOnce(dispatcher); |
65 | 70 |
|
66 | 71 | await fetchWithTimeout('url'); |
67 | 72 |
|
68 | | - expect(global.fetch).toHaveBeenCalledWith('url', { dispatcher: proxyAgent }); |
| 73 | + expect(global.fetch).toHaveBeenCalledWith('url', { dispatcher }); |
69 | 74 | }); |
70 | 75 |
|
71 | 76 | it('should call fetch without signal when timeout is not passed', async () => { |
|
0 commit comments