| 91 | private matchers: RequestMatcher[] = []; |
| 92 | |
| 93 | async start(options: MockServerOptions = {}): Promise<{ port: number; baseURL: string }> { |
| 94 | const port = options.port ?? 0; // 0 = pick any available port |
| 95 | this.server = Bun.serve({ |
| 96 | port, |
| 97 | fetch: async (req) => this.handle(req), |
| 98 | }); |
| 99 | const actualPort = this.server.port ?? 0; |
| 100 | if (!actualPort) throw new Error("mock server failed to bind a port"); |
| 101 | return { port: actualPort, baseURL: `http://127.0.0.1:${actualPort}` }; |
| 102 | } |
| 103 | |
| 104 | async stop(): Promise<void> { |
| 105 | if (this.server) { |