Skip to content

Add flag for toggling permessage-deflate #3286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Refactor integration tests to use main entry point
  • Loading branch information
code-asher committed May 5, 2021
commit a882be574887367b378658535d2414e09e591ad5
3 changes: 2 additions & 1 deletion src/node/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async function entry(): Promise<void> {
if (isChild(wrapper)) {
const args = await wrapper.handshake()
wrapper.preventExit()
return runCodeServer(args)
await runCodeServer(args)
return
}

const cliArgs = parse(process.argv.slice(2))
Expand Down
4 changes: 3 additions & 1 deletion src/node/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const openInExistingInstance = async (args: DefaultedArgs, socketPath: st
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(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
Expand Down Expand Up @@ -154,4 +154,6 @@ export const runCodeServer = async (args: DefaultedArgs): Promise<void> => {
logger.error("Failed to open", field("address", openAddress), field("error", error))
}
}

return server
}
4 changes: 2 additions & 2 deletions test/unit/health.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe("health", () => {
})

it("/healthz", async () => {
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks way cleaner/easier to read 👏

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yea, the code before was 🤨 kinda inscrutable, but then again, I'm not a JavaScript/TypeScript person

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"], "")
codeServer = await integration.setup(["--auth=none"], "")
const ws = codeServer.ws("/healthz")
const message = await new Promise((resolve, reject) => {
ws.on("error", console.error)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("proxy", () => {
e.get("/wsup", (req, res) => {
res.json("asher is the best")
})
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath)
expect(resp.status).toBe(200)
const json = await resp.json()
Expand All @@ -48,7 +48,7 @@ describe("proxy", () => {
e.get(absProxyPath, (req, res) => {
res.json("joe is the best")
})
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(absProxyPath)
expect(resp.status).toBe(200)
const json = await resp.json()
Expand All @@ -62,7 +62,7 @@ describe("proxy", () => {
e.post("/finale", (req, res) => {
res.json("redirect success")
})
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath, {
method: "POST",
})
Expand All @@ -78,7 +78,7 @@ describe("proxy", () => {
e.post(finalePath, (req, res) => {
res.json("redirect success")
})
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(absProxyPath, {
method: "POST",
})
Expand All @@ -91,7 +91,7 @@ describe("proxy", () => {
e.post("/wsup", (req, res) => {
res.json(req.body)
})
;[, , codeServer] = await integration.setup(["--auth=none"], "")
codeServer = await integration.setup(["--auth=none"], "")
const resp = await codeServer.fetch(proxyPath, {
method: "post",
body: JSON.stringify("coder is the best"),
Expand Down
16 changes: 5 additions & 11 deletions test/utils/integration.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import * as express from "express"
import { createApp } from "../../src/node/app"
import { parse, setDefaults, parseConfigFile, DefaultedArgs } from "../../src/node/cli"
import { register } from "../../src/node/routes"
import { parse, parseConfigFile, setDefaults } from "../../src/node/cli"
import { runCodeServer } from "../../src/node/main"
import * as httpserver from "./httpserver"

export async function setup(
argv: string[],
configFile?: string,
): Promise<[express.Application, express.Application, httpserver.HttpServer, DefaultedArgs]> {
export async function setup(argv: string[], configFile?: string): Promise<httpserver.HttpServer> {
argv = ["--bind-addr=localhost:0", ...argv]

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

const [app, wsApp, server] = await createApp(args)
await register(app, wsApp, server, args)
const server = await runCodeServer(args)

return [app, wsApp, new httpserver.HttpServer(server), args]
return new httpserver.HttpServer(server)
}