Archived
1
0

Refactor integration tests to use main entry point

This commit is contained in:
Asher 2021-05-05 12:20:38 -05:00
parent 20e70cfa05
commit a882be5748
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
5 changed files with 17 additions and 20 deletions

View File

@ -24,7 +24,8 @@ async function entry(): Promise<void> {
if (isChild(wrapper)) { if (isChild(wrapper)) {
const args = await wrapper.handshake() const args = await wrapper.handshake()
wrapper.preventExit() wrapper.preventExit()
return runCodeServer(args) await runCodeServer(args)
return
} }
const cliArgs = parse(process.argv.slice(2)) const cliArgs = parse(process.argv.slice(2))

View File

@ -82,7 +82,7 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
vscode.end() vscode.end()
} }
export const runCodeServer = async (args: DefaultedArgs): Promise<void> => { export const runCodeServer = async (args: DefaultedArgs): Promise<http.Server> => {
logger.info(`code-server ${version} ${commit}`) logger.info(`code-server ${version} ${commit}`)
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`) logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
@ -154,4 +154,6 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<void> => {
logger.error("Failed to open", field("address", openAddress), field("error", error)) logger.error("Failed to open", field("address", openAddress), field("error", error))
} }
} }
return server
} }

View File

@ -12,7 +12,7 @@ describe("health", () => {
}) })
it("/healthz", async () => { it("/healthz", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch("/healthz") const resp = await codeServer.fetch("/healthz")
expect(resp.status).toBe(200) expect(resp.status).toBe(200)
const json = await resp.json() const json = await resp.json()
@ -20,7 +20,7 @@ describe("health", () => {
}) })
it("/healthz (websocket)", async () => { it("/healthz (websocket)", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const ws = codeServer.ws("/healthz") const ws = codeServer.ws("/healthz")
const message = await new Promise((resolve, reject) => { const message = await new Promise((resolve, reject) => {
ws.on("error", console.error) ws.on("error", console.error)

View File

@ -37,7 +37,7 @@ describe("proxy", () => {
e.get("/wsup", (req, res) => { e.get("/wsup", (req, res) => {
res.json("asher is the best") res.json("asher is the best")
}) })
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath) const resp = await codeServer.fetch(proxyPath)
expect(resp.status).toBe(200) expect(resp.status).toBe(200)
const json = await resp.json() const json = await resp.json()
@ -48,7 +48,7 @@ describe("proxy", () => {
e.get(absProxyPath, (req, res) => { e.get(absProxyPath, (req, res) => {
res.json("joe is the best") res.json("joe is the best")
}) })
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(absProxyPath) const resp = await codeServer.fetch(absProxyPath)
expect(resp.status).toBe(200) expect(resp.status).toBe(200)
const json = await resp.json() const json = await resp.json()
@ -62,7 +62,7 @@ describe("proxy", () => {
e.post("/finale", (req, res) => { e.post("/finale", (req, res) => {
res.json("redirect success") res.json("redirect success")
}) })
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath, { const resp = await codeServer.fetch(proxyPath, {
method: "POST", method: "POST",
}) })
@ -78,7 +78,7 @@ describe("proxy", () => {
e.post(finalePath, (req, res) => { e.post(finalePath, (req, res) => {
res.json("redirect success") res.json("redirect success")
}) })
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(absProxyPath, { const resp = await codeServer.fetch(absProxyPath, {
method: "POST", method: "POST",
}) })
@ -91,7 +91,7 @@ describe("proxy", () => {
e.post("/wsup", (req, res) => { e.post("/wsup", (req, res) => {
res.json(req.body) res.json(req.body)
}) })
;[, , codeServer] = await integration.setup(["--auth=none"], "") codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath, { const resp = await codeServer.fetch(proxyPath, {
method: "post", method: "post",
body: JSON.stringify("coder is the best"), body: JSON.stringify("coder is the best"),

View File

@ -1,21 +1,15 @@
import * as express from "express" import { parse, parseConfigFile, setDefaults } from "../../src/node/cli"
import { createApp } from "../../src/node/app" import { runCodeServer } from "../../src/node/main"
import { parse, setDefaults, parseConfigFile, DefaultedArgs } from "../../src/node/cli"
import { register } from "../../src/node/routes"
import * as httpserver from "./httpserver" import * as httpserver from "./httpserver"
export async function setup( export async function setup(argv: string[], configFile?: string): Promise<httpserver.HttpServer> {
argv: string[],
configFile?: string,
): Promise<[express.Application, express.Application, httpserver.HttpServer, DefaultedArgs]> {
argv = ["--bind-addr=localhost:0", ...argv] argv = ["--bind-addr=localhost:0", ...argv]
const cliArgs = parse(argv) const cliArgs = parse(argv)
const configArgs = parseConfigFile(configFile || "", "test/integration.ts") const configArgs = parseConfigFile(configFile || "", "test/integration.ts")
const args = await setDefaults(cliArgs, configArgs) const args = await setDefaults(cliArgs, configArgs)
const [app, wsApp, server] = await createApp(args) const server = await runCodeServer(args)
await register(app, wsApp, server, args)
return [app, wsApp, new httpserver.HttpServer(server), args] return new httpserver.HttpServer(server)
} }