diff --git a/test/integration.ts b/test/integration.ts deleted file mode 100644 index f829fe5d..00000000 --- a/test/integration.ts +++ /dev/null @@ -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] -} diff --git a/test/constants.ts b/test/utils/constants.ts similarity index 80% rename from test/constants.ts rename to test/utils/constants.ts index ac2250e1..9a750892 100644 --- a/test/constants.ts +++ b/test/utils/constants.ts @@ -1,3 +1,4 @@ export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080" export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab" export const STORAGE = process.env.STORAGE || "" +export const E2E_VIDEO_DIR = "./test/e2e/videos" diff --git a/test/cssStub.ts b/test/utils/cssStub.ts similarity index 100% rename from test/cssStub.ts rename to test/utils/cssStub.ts diff --git a/test/globalSetup.ts b/test/utils/globalSetup.ts similarity index 87% rename from test/globalSetup.ts rename to test/utils/globalSetup.ts index 5ef45faa..36b242d7 100644 --- a/test/globalSetup.ts +++ b/test/utils/globalSetup.ts @@ -6,7 +6,7 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants" import * as wtfnode from "./wtfnode" 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...") const browser = await chromium.launch() const context = await browser.newContext() @@ -30,5 +30,5 @@ module.exports = async () => { await page.close() await browser.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.") } diff --git a/test/helpers.ts b/test/utils/helpers.ts similarity index 100% rename from test/helpers.ts rename to test/utils/helpers.ts diff --git a/test/httpserver.ts b/test/utils/httpserver.ts similarity index 95% rename from test/httpserver.ts rename to test/utils/httpserver.ts index 399ccda1..a66bbbff 100644 --- a/test/httpserver.ts +++ b/test/utils/httpserver.ts @@ -3,9 +3,9 @@ import * as http from "http" import * as net from "net" import * as nodeFetch from "node-fetch" import Websocket from "ws" -import * as util from "../src/common/util" -import { ensureAddress } from "../src/node/app" -import { handleUpgrade } from "../src/node/wsRouter" +import * as util from "../../src/common/util" +import { ensureAddress } from "../../src/node/app" +import { handleUpgrade } from "../../src/node/wsRouter" // Perhaps an abstraction similar to this should be used in app.ts as well. export class HttpServer { diff --git a/test/utils/wtfnode.ts b/test/utils/wtfnode.ts new file mode 100644 index 00000000..2d31a4e6 --- /dev/null +++ b/test/utils/wtfnode.ts @@ -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() +}