UNPKG

opinionated-machine

Version:

Very opinionated DI framework for fastify, built on top of awilix

56 lines (55 loc) 1.82 kB
import type { AnyFastifyInstance } from './AnyFastifyInstance.ts'; /** * Test server wrapper that starts a Fastify app on a random port for testing. * * Use `SSETestServer.start(app)` with your pre-configured Fastify app: * * ```typescript * const app = getApp() // your app factory * const server = await SSETestServer.start(app) * // server.baseUrl → "http://localhost:xxxxx" * // server.app → the Fastify instance * * const { client } = await SSEHttpClient.connect(server.baseUrl, '/api/events', ...) * // ... test ... * client.close() * await server.close() * ``` */ export declare class SSETestServer { /** The Fastify instance */ readonly app: AnyFastifyInstance; /** Base URL for the running server (e.g., "http://localhost:3000") */ readonly baseUrl: string; private constructor(); /** * Start a pre-configured Fastify app on a random port for testing. * * The app should have routes and plugins already registered — * this method only starts the HTTP listener. * * @param app - A fully configured Fastify instance (routes, plugins, etc. already registered) * @returns A running SSETestServer with `baseUrl` and `app` * * @example * ```typescript * const app = getApp() // your app factory that creates & configures Fastify * const server = await SSETestServer.start(app) * * const { client } = await SSEHttpClient.connect( * server.baseUrl, * '/api/events', * { awaitServerConnection: { controller } }, * ) * * // ... test ... * client.close() * await server.close() * ``` */ static start(app: AnyFastifyInstance): Promise<SSETestServer>; /** * Close the server and cleanup resources. */ close(): Promise<void>; }