mirror of https://github.com/coder/code-server.git
refactor: create test/utils
This commit is contained in:
parent
b468597872
commit
cf6fdb90eb
|
@ -1,21 +0,0 @@
|
||||||
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 * as httpserver from "./httpserver"
|
|
||||||
|
|
||||||
export async function setup(
|
|
||||||
argv: string[],
|
|
||||||
configFile?: string,
|
|
||||||
): Promise<[express.Application, express.Application, httpserver.HttpServer, DefaultedArgs]> {
|
|
||||||
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)
|
|
||||||
|
|
||||||
return [app, wsApp, new httpserver.HttpServer(server), args]
|
|
||||||
}
|
|
|
@ -1,3 +1,4 @@
|
||||||
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
|
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
|
||||||
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
|
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
|
||||||
export const STORAGE = process.env.STORAGE || ""
|
export const STORAGE = process.env.STORAGE || ""
|
||||||
|
export const E2E_VIDEO_DIR = "./test/e2e/videos"
|
|
@ -6,7 +6,7 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
|
||||||
import * as wtfnode from "./wtfnode"
|
import * as wtfnode from "./wtfnode"
|
||||||
|
|
||||||
module.exports = async () => {
|
module.exports = async () => {
|
||||||
console.log("\n🚨 Running Global Setup for Jest Tests")
|
console.log("\n🚨 Running Global Setup for Jest End-to-End Tests")
|
||||||
console.log(" Please hang tight...")
|
console.log(" Please hang tight...")
|
||||||
const browser = await chromium.launch()
|
const browser = await chromium.launch()
|
||||||
const context = await browser.newContext()
|
const context = await browser.newContext()
|
||||||
|
@ -30,5 +30,5 @@ module.exports = async () => {
|
||||||
await page.close()
|
await page.close()
|
||||||
await browser.close()
|
await browser.close()
|
||||||
await context.close()
|
await context.close()
|
||||||
console.log("✅ Global Setup for Jest Tests is now complete.")
|
console.log("✅ Global Setup for Jest End-to-End Tests is now complete.")
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@ import * as http from "http"
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import * as nodeFetch from "node-fetch"
|
import * as nodeFetch from "node-fetch"
|
||||||
import Websocket from "ws"
|
import Websocket from "ws"
|
||||||
import * as util from "../src/common/util"
|
import * as util from "../../src/common/util"
|
||||||
import { ensureAddress } from "../src/node/app"
|
import { ensureAddress } from "../../src/node/app"
|
||||||
import { handleUpgrade } from "../src/node/wsRouter"
|
import { handleUpgrade } from "../../src/node/wsRouter"
|
||||||
|
|
||||||
// Perhaps an abstraction similar to this should be used in app.ts as well.
|
// Perhaps an abstraction similar to this should be used in app.ts as well.
|
||||||
export class HttpServer {
|
export class HttpServer {
|
|
@ -0,0 +1,35 @@
|
||||||
|
import * as util from "util"
|
||||||
|
import * as wtfnode from "wtfnode"
|
||||||
|
|
||||||
|
// Jest seems to hijack console.log in a way that makes the output difficult to
|
||||||
|
// read. So we'll write directly to process.stderr instead.
|
||||||
|
const write = (...args: [any, ...any]) => {
|
||||||
|
if (args.length > 0) {
|
||||||
|
process.stderr.write(util.format(...args) + "\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wtfnode.setLogger("info", write)
|
||||||
|
wtfnode.setLogger("warn", write)
|
||||||
|
wtfnode.setLogger("error", write)
|
||||||
|
|
||||||
|
let active = false
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start logging open handles periodically. This can be used to see what is
|
||||||
|
* hanging open if anything.
|
||||||
|
*/
|
||||||
|
export function setup(): void {
|
||||||
|
if (active) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
active = true
|
||||||
|
|
||||||
|
const interval = 5000
|
||||||
|
const wtfnodeDump = () => {
|
||||||
|
wtfnode.dump()
|
||||||
|
const t = setTimeout(wtfnodeDump, interval)
|
||||||
|
t.unref()
|
||||||
|
}
|
||||||
|
const t = setTimeout(wtfnodeDump, interval)
|
||||||
|
t.unref()
|
||||||
|
}
|
Loading…
Reference in New Issue