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