refactor: add helper fn getMaybeProxiedPathname
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { promises as fs } from "fs"
|
||||
import { clean, getAvailablePort, tmpdir, useEnv } from "../../test/utils/helpers"
|
||||
import { clean, getAvailablePort, getMaybeProxiedPathname, tmpdir, useEnv } from "../../test/utils/helpers"
|
||||
import { REVERSE_PROXY_BASE_PATH } from "../utils/constants"
|
||||
|
||||
/**
|
||||
* This file is for testing test helpers (not core code).
|
||||
@ -56,3 +57,22 @@ describe("getAvailablePort", () => {
|
||||
expect(portOne).not.toEqual(portTwo)
|
||||
})
|
||||
})
|
||||
|
||||
describe("getMaybeProxiedPathname", () => {
|
||||
it("should return the route", () => {
|
||||
const route = "/vscode"
|
||||
const url = new URL(`http://localhost:3000${route}`)
|
||||
const actual = getMaybeProxiedPathname(url)
|
||||
expect(actual).toBe(route)
|
||||
})
|
||||
it("should strip proxy if env var set", () => {
|
||||
const envKey = "USE_PROXY"
|
||||
const [setValue, resetValue] = useEnv(envKey)
|
||||
setValue("1")
|
||||
const route = "/vscode"
|
||||
const url = new URL(`http://localhost:3000/8000/${REVERSE_PROXY_BASE_PATH}${route}`)
|
||||
const actual = getMaybeProxiedPathname(url)
|
||||
expect(actual).toBe(route)
|
||||
resetValue()
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user