mirror of
https://github.com/coder/code-server.git
synced 2025-07-29 21:12:58 +08:00
test: Implement integration.ts for near full stack integration testing
This commit is contained in:
@ -3,9 +3,17 @@ import * as nodeFetch from "node-fetch"
|
||||
import * as util from "../src/common/util"
|
||||
import { ensureAddress } from "../src/node/app"
|
||||
|
||||
// Perhaps an abstraction similar to this should be used in app.ts as well.
|
||||
export class HttpServer {
|
||||
private hs = http.createServer()
|
||||
|
||||
public constructor(hs?: http.Server) {
|
||||
// See usage in test/integration.ts
|
||||
if (hs) {
|
||||
this.hs = hs
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* listen starts the server on a random localhost port.
|
||||
* Use close to cleanup when done.
|
||||
@ -53,4 +61,12 @@ export class HttpServer {
|
||||
public fetch(requestPath: string, opts?: nodeFetch.RequestInit): Promise<nodeFetch.Response> {
|
||||
return nodeFetch.default(`${ensureAddress(this.hs)}${requestPath}`, opts)
|
||||
}
|
||||
|
||||
public port(): number {
|
||||
const addr = this.hs.address()
|
||||
if (addr && typeof addr == "object") {
|
||||
return addr.port
|
||||
}
|
||||
throw new Error("server not listening or listening on unix socket")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user