2021-07-24 00:38:25 +03:00
|
|
|
import { shouldEnableProxy } from "../../../src/node/proxy_agent"
|
2021-07-26 21:21:30 +03:00
|
|
|
import { useEnv } from "../../utils/helpers"
|
2021-07-24 00:38:25 +03:00
|
|
|
|
|
|
|
describe("shouldEnableProxy", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
const [setHTTPProxy, resetHTTPProxy] = useEnv("HTTP_PROXY")
|
|
|
|
const [setHTTPSProxy, resetHTTPSProxy] = useEnv("HTTPS_PROXY")
|
|
|
|
const [setNoProxy, resetNoProxy] = useEnv("NO_PROXY")
|
2021-07-24 00:38:25 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.resetModules() // Most important - it clears the cache
|
2021-07-26 21:21:30 +03:00
|
|
|
resetHTTPProxy()
|
|
|
|
resetNoProxy()
|
|
|
|
resetHTTPSProxy()
|
2021-07-24 00:38:25 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
it("returns true when HTTP_PROXY is set", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
setHTTPProxy("http://proxy.example.com")
|
2021-07-24 00:38:25 +03:00
|
|
|
expect(shouldEnableProxy()).toBe(true)
|
|
|
|
})
|
|
|
|
it("returns true when HTTPS_PROXY is set", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
setHTTPSProxy("https://proxy.example.com")
|
2021-07-24 00:38:25 +03:00
|
|
|
expect(shouldEnableProxy()).toBe(true)
|
|
|
|
})
|
|
|
|
it("returns false when NO_PROXY is set", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
setNoProxy("*")
|
2021-07-24 00:38:25 +03:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when neither HTTP_PROXY nor HTTPS_PROXY is set", () => {
|
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when NO_PROXY is set to https://example.com", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
setNoProxy("https://example.com")
|
2021-07-24 00:38:25 +03:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
it("should return false when NO_PROXY is set to http://example.com", () => {
|
2021-07-26 21:21:30 +03:00
|
|
|
setNoProxy("http://example.com")
|
2021-07-24 00:38:25 +03:00
|
|
|
expect(shouldEnableProxy()).toBe(false)
|
|
|
|
})
|
|
|
|
})
|