test: use proxy in tests

This commit is contained in:
WebStreamr 2025-08-15 10:32:43 +00:00
parent fe5b3af887
commit 9854d3b5b6
No known key found for this signature in database

View file

@ -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 }));
}
}