CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s
Co-Authored-By: gpt-5.6-terra <noreply@openai.com>
30 lines
902 B
TypeScript
30 lines
902 B
TypeScript
import Koa from "koa";
|
|
import { createServer } from "node:http";
|
|
import type { AddressInfo } from "node:net";
|
|
import { apirouter } from "../../src/webapi/apirouter.js";
|
|
import type { BackendDbInterface } from "../../src/db/types/DbInterface.js";
|
|
|
|
export interface TestServer {
|
|
url: string;
|
|
close(): Promise<void>;
|
|
}
|
|
|
|
export async function createTestServer(
|
|
db: BackendDbInterface,
|
|
): Promise<TestServer> {
|
|
const app = new Koa();
|
|
const router = apirouter(db);
|
|
app.use(router.routes());
|
|
app.use(router.allowedMethods());
|
|
const server = createServer(app.callback());
|
|
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
const { port } = server.address() as AddressInfo;
|
|
return {
|
|
url: `http://127.0.0.1:${port}`,
|
|
close: () =>
|
|
new Promise<void>((resolve, reject) =>
|
|
server.close((err) => (err ? reject(err) : resolve())),
|
|
),
|
|
};
|
|
}
|