1import { wrapFetchWithProxy } from '../wrapFetchWithProxy';
2
3const originalEnv = process.env;
4
5afterAll(() => {
6  process.env = originalEnv;
7});
8
9describe(wrapFetchWithProxy, () => {
10  it(`supports normal requests`, async () => {
11    delete process.env.HTTP_PROXY;
12
13    const input = jest.fn();
14    const next = wrapFetchWithProxy(input);
15    await next('https://example.com/', {});
16    expect(input).toBeCalledWith('https://example.com/', {});
17  });
18  it(`proxies requests`, async () => {
19    process.env.HTTP_PROXY = 'http://localhost:8080';
20    const input = jest.fn();
21    const next = wrapFetchWithProxy(input);
22    await next('https://example.com/', {});
23    expect(input).toBeCalledWith('https://example.com/', {
24      agent: expect.objectContaining({
25        proxy: expect.objectContaining({
26          host: 'localhost',
27        }),
28      }),
29    });
30  });
31});
32