From 9854d3b5b6e01a09d6e10e71f3365fabc1d0c4ef Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Fri, 15 Aug 2025 10:32:43 +0000 Subject: [PATCH] test: use proxy in tests --- jest.setup.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jest.setup.ts b/jest.setup.ts index 2ac8cec..d8d34fd 100644 --- a/jest.setup.ts +++ b/jest.setup.ts @@ -1,3 +1,6 @@ +import { socksDispatcher } from 'fetch-socks'; +import { ProxyAgent, setGlobalDispatcher } from 'undici'; + jest.mock('randomstring', () => ({ generate: jest.fn(() => 'mocked-random-string'), })); @@ -5,3 +8,12 @@ jest.mock('randomstring', () => ({ beforeEach(() => { jest.spyOn(Date, 'now').mockImplementation(() => 639837296000); }); + +if (process.env['ALL_PROXY']) { + const proxyUrl = new URL(process.env['ALL_PROXY']); + if (proxyUrl.protocol === 'socks5:') { + setGlobalDispatcher(socksDispatcher({ type: 5, host: proxyUrl.hostname, port: parseInt(proxyUrl.port) })); + } else { + setGlobalDispatcher(new ProxyAgent({ uri: proxyUrl.href })); + } +}