Skip to content

Commit a882be5

Browse files
committed
Refactor integration tests to use main entry point
1 parent 20e70cf commit a882be5

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

src/node/entry.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ async function entry(): Promise<void> {
2424
if (isChild(wrapper)) {
2525
const args = await wrapper.handshake()
2626
wrapper.preventExit()
27-
return runCodeServer(args)
27+
await runCodeServer(args)
28+
return
2829
}
2930

3031
const cliArgs = parse(process.argv.slice(2))

src/node/main.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
8282
vscode.end()
8383
}
8484

85-
export const runCodeServer = async (args: DefaultedArgs): Promise<void> => {
85+
export const runCodeServer = async (args: DefaultedArgs): Promise<http.Server> => {
8686
logger.info(`code-server ${version} ${commit}`)
8787

8888
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
@@ -154,4 +154,6 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<void> => {
154154
logger.error("Failed to open", field("address", openAddress), field("error", error))
155155
}
156156
}
157+
158+
return server
157159
}

test/unit/health.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ describe("health", () => {
1212
})
1313

1414
it("/healthz", async () => {
15-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
15+
codeServer = await integration.setup(["--auth=none"], "")
1616
const resp = await codeServer.fetch("/healthz")
1717
expect(resp.status).toBe(200)
1818
const json = await resp.json()
1919
expect(json).toStrictEqual({ lastHeartbeat: 0, status: "expired" })
2020
})
2121

2222
it("/healthz (websocket)", async () => {
23-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
23+
codeServer = await integration.setup(["--auth=none"], "")
2424
const ws = codeServer.ws("/healthz")
2525
const message = await new Promise((resolve, reject) => {
2626
ws.on("error", console.error)

test/unit/proxy.test.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("proxy", () => {
3737
e.get("/wsup", (req, res) => {
3838
res.json("asher is the best")
3939
})
40-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
40+
codeServer = await integration.setup(["--auth=none"], "")
4141
const resp = await codeServer.fetch(proxyPath)
4242
expect(resp.status).toBe(200)
4343
const json = await resp.json()
@@ -48,7 +48,7 @@ describe("proxy", () => {
4848
e.get(absProxyPath, (req, res) => {
4949
res.json("joe is the best")
5050
})
51-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
51+
codeServer = await integration.setup(["--auth=none"], "")
5252
const resp = await codeServer.fetch(absProxyPath)
5353
expect(resp.status).toBe(200)
5454
const json = await resp.json()
@@ -62,7 +62,7 @@ describe("proxy", () => {
6262
e.post("/finale", (req, res) => {
6363
res.json("redirect success")
6464
})
65-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
65+
codeServer = await integration.setup(["--auth=none"], "")
6666
const resp = await codeServer.fetch(proxyPath, {
6767
method: "POST",
6868
})
@@ -78,7 +78,7 @@ describe("proxy", () => {
7878
e.post(finalePath, (req, res) => {
7979
res.json("redirect success")
8080
})
81-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
81+
codeServer = await integration.setup(["--auth=none"], "")
8282
const resp = await codeServer.fetch(absProxyPath, {
8383
method: "POST",
8484
})
@@ -91,7 +91,7 @@ describe("proxy", () => {
9191
e.post("/wsup", (req, res) => {
9292
res.json(req.body)
9393
})
94-
;[, , codeServer] = await integration.setup(["--auth=none"], "")
94+
codeServer = await integration.setup(["--auth=none"], "")
9595
const resp = await codeServer.fetch(proxyPath, {
9696
method: "post",
9797
body: JSON.stringify("coder is the best"),

test/utils/integration.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
import * as express from "express"
2-
import { createApp } from "../../src/node/app"
3-
import { parse, setDefaults, parseConfigFile, DefaultedArgs } from "../../src/node/cli"
4-
import { register } from "../../src/node/routes"
1+
import { parse, parseConfigFile, setDefaults } from "../../src/node/cli"
2+
import { runCodeServer } from "../../src/node/main"
53
import * as httpserver from "./httpserver"
64

7-
export async function setup(
8-
argv: string[],
9-
configFile?: string,
10-
): Promise<[express.Application, express.Application, httpserver.HttpServer, DefaultedArgs]> {
5+
export async function setup(argv: string[], configFile?: string): Promise<httpserver.HttpServer> {
116
argv = ["--bind-addr=localhost:0", ...argv]
127

138
const cliArgs = parse(argv)
149
const configArgs = parseConfigFile(configFile || "", "test/integration.ts")
1510
const args = await setDefaults(cliArgs, configArgs)
1611

17-
const [app, wsApp, server] = await createApp(args)
18-
await register(app, wsApp, server, args)
12+
const server = await runCodeServer(args)
1913

20-
return [app, wsApp, new httpserver.HttpServer(server), args]
14+
return new httpserver.HttpServer(server)
2115
}

0 commit comments

Comments
 (0)