test: use proxy in tests
This commit is contained in:
parent
fe5b3af887
commit
9854d3b5b6
1 changed files with 12 additions and 0 deletions
|
|
@ -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 }));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue