Live video on the AT Protocol
1import { AppContext, Database, PlcServer } from "@did-plc/server";
2
3import getPort from "get-port";
4
5export interface PlcServerOptions {
6 port?: number;
7}
8
9export class TestPlcServer {
10 constructor(
11 public readonly server: PlcServer,
12 public readonly url: string,
13 public readonly port: number,
14 ) {}
15
16 static async create(cfg: PlcServerOptions = {}): Promise<TestPlcServer> {
17 const port = cfg.port ?? (await getPort());
18 const url = `http://localhost:${port}`;
19
20 const db = Database.mock();
21 const server = PlcServer.create({ db, port });
22
23 await server.start();
24
25 return new TestPlcServer(server, url, port);
26 }
27
28 get context(): AppContext {
29 return this.server.ctx;
30 }
31
32 async close() {
33 await this.server.destroy();
34 }
35}