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/app.test.ts
Joe Previte 09440563ca
feat: add tests for src/node/app.ts
This adds a couple tests for ensureAddress.
2021-09-09 17:58:36 -07:00

31 lines
917 B
TypeScript

import * as http from "http"
import { ensureAddress } from "../../../src/node/app"
import { getAvailablePort } from "../../utils/helpers"
describe("ensureAddress", () => {
let mockServer: http.Server
beforeEach(() => {
mockServer = http.createServer()
})
afterEach(() => {
mockServer.close()
})
it("should throw and error if no address", () => {
expect(() => ensureAddress(mockServer)).toThrow("server has no address")
})
it("should return the address if it exists and not a string", async () => {
const port = await getAvailablePort()
mockServer.listen(port)
const address = ensureAddress(mockServer)
expect(address).toBe(`http://:::${port}`)
})
it("should return the address if it exists", async () => {
mockServer.address = () => "http://localhost:8080"
const address = ensureAddress(mockServer)
expect(address).toBe(`http://localhost:8080`)
})
})