Archived
1
0

refactor: open function (#5257)

* refactor: fix type annotations in open

There was no clear reason as to why we needed to use type assertions
when initializing both `args` and `options` in `open` so I refactored
them both.

* refactor: create constructOpenOptions

* refactor: add urlSearch and remove options

* feat: add tests for constructOpenOptions
This commit is contained in:
Joe Previte
2022-06-15 13:53:07 -07:00
committed by GitHub
parent 113ad85b37
commit 61138b4a61
2 changed files with 68 additions and 9 deletions

View File

@ -544,3 +544,37 @@ describe("open", () => {
await expect(util.open(address)).rejects.toThrow("Cannot open socket paths")
})
})
describe("constructOpenOptions", () => {
it("should return options for darwin", () => {
const platform: NodeJS.Platform | "wsl" = "darwin"
const url = new URL("localhost:8080")
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
expect(args).toStrictEqual([])
expect(command).toBe("open")
expect(urlSearch).toBe("")
})
it("should return options for linux", () => {
const platform: NodeJS.Platform | "wsl" = "linux"
const url = new URL("localhost:8080")
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
expect(args).toStrictEqual([])
expect(command).toBe("xdg-open")
expect(urlSearch).toBe("")
})
it("should return options for win32", () => {
const platform: NodeJS.Platform | "wsl" = "win32"
const url = new URL("localhost:8080?q=&test")
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
expect(args).toStrictEqual(["/c", "start", '""', "/b"])
expect(command).toBe("cmd")
expect(urlSearch).toBe("?q=^&test")
})
it("should return options for wsl", () => {
const platform: NodeJS.Platform | "wsl" = "wsl"
const url = new URL("localhost:8080?q=&test")
const { args, command, urlSearch } = util.constructOpenOptions(platform, url.search)
expect(args).toStrictEqual(["/c", "start", '""', "/b"])
expect(command).toBe("cmd.exe")
expect(urlSearch).toBe("?q=^&test")
})
})