Archived
1
0
This repository has been archived on 2024-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
code-server/test/unit/node/proxy_agent.test.ts

44 lines
1.4 KiB
TypeScript
Raw Normal View History

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