Skip to content

Commit cf6fdb9

Browse files
committed
refactor: create test/utils
1 parent b468597 commit cf6fdb9

File tree

7 files changed

+41
-26
lines changed

7 files changed

+41
-26
lines changed

test/integration.ts

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const CODE_SERVER_ADDRESS = process.env.CODE_SERVER_ADDRESS || "http://localhost:8080"
22
export const PASSWORD = process.env.PASSWORD || "e45432jklfdsab"
33
export const STORAGE = process.env.STORAGE || ""
4+
export const E2E_VIDEO_DIR = "./test/e2e/videos"
File renamed without changes.

test/globalSetup.ts renamed to test/utils/globalSetup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CODE_SERVER_ADDRESS, PASSWORD } from "./constants"
66
import * as wtfnode from "./wtfnode"
77

88
module.exports = async () => {
9-
console.log("\n🚨 Running Global Setup for Jest Tests")
9+
console.log("\n🚨 Running Global Setup for Jest End-to-End Tests")
1010
console.log(" Please hang tight...")
1111
const browser = await chromium.launch()
1212
const context = await browser.newContext()
@@ -30,5 +30,5 @@ module.exports = async () => {
3030
await page.close()
3131
await browser.close()
3232
await context.close()
33-
console.log("✅ Global Setup for Jest Tests is now complete.")
33+
console.log("✅ Global Setup for Jest End-to-End Tests is now complete.")
3434
}
File renamed without changes.

test/httpserver.ts renamed to test/utils/httpserver.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import * as http from "http"
33
import * as net from "net"
44
import * as nodeFetch from "node-fetch"
55
import Websocket from "ws"
6-
import * as util from "../src/common/util"
7-
import { ensureAddress } from "../src/node/app"
8-
import { handleUpgrade } from "../src/node/wsRouter"
6+
import * as util from "../../src/common/util"
7+
import { ensureAddress } from "../../src/node/app"
8+
import { handleUpgrade } from "../../src/node/wsRouter"
99

1010
// Perhaps an abstraction similar to this should be used in app.ts as well.
1111
export class HttpServer {

test/utils/wtfnode.ts

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as util from "util"
2+
import * as wtfnode from "wtfnode"
3+
4+
// Jest seems to hijack console.log in a way that makes the output difficult to
5+
// read. So we'll write directly to process.stderr instead.
6+
const write = (...args: [any, ...any]) => {
7+
if (args.length > 0) {
8+
process.stderr.write(util.format(...args) + "\n")
9+
}
10+
}
11+
wtfnode.setLogger("info", write)
12+
wtfnode.setLogger("warn", write)
13+
wtfnode.setLogger("error", write)
14+
15+
let active = false
16+
17+
/**
18+
* Start logging open handles periodically. This can be used to see what is
19+
* hanging open if anything.
20+
*/
21+
export function setup(): void {
22+
if (active) {
23+
return
24+
}
25+
active = true
26+
27+
const interval = 5000
28+
const wtfnodeDump = () => {
29+
wtfnode.dump()
30+
const t = setTimeout(wtfnodeDump, interval)
31+
t.unref()
32+
}
33+
const t = setTimeout(wtfnodeDump, interval)
34+
t.unref()
35+
}

0 commit comments

Comments
 (0)