1
0
mirror of https://git.tuxpa.in/a/code-server.git synced 2024-12-30 22:18:44 +00:00
code-server-2/test/unit/health.test.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-03-09 23:32:31 +00:00
import * as httpserver from "../utils/httpserver"
import * as integration from "../utils/integration"
2021-02-16 20:14:21 +00:00
describe("health", () => {
let codeServer: httpserver.HttpServer | undefined
afterEach(async () => {
if (codeServer) {
await codeServer.close()
codeServer = undefined
}
})
it("/healthz", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch("/healthz")
expect(resp.status).toBe(200)
const json = await resp.json()
expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" })
})
it("/healthz (websocket)", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "")
const ws = codeServer.ws("/healthz")
const message = await new Promise((resolve, reject) => {
ws.on("error", console.error)
ws.on("message", (message) => {
try {
const j = JSON.parse(message.toString())
resolve(j)
} catch (error) {
reject(error)
}
})
ws.on("open", () => ws.send(JSON.stringify({ event: "health" })))
})
ws.terminate()
expect(message).toStrictEqual({ event: "health", status: "expired", lastHeartbeat: 0 })
})
})