import { type HttpApp, type HttpOptions } from '@dunx/http'; import { type TestAppOptions } from './app.js'; import { TestClient } from './client.js'; export interface TestServerOptions extends TestAppOptions, Omit { /** * `setGlobalPrefix`, applied before `listen()` so the client's URLs carry it. * * Explicitly `| undefined`, unlike the rest of the options: a suite that runs * the same fixture prefixed and unprefixed passes a variable here, and under * `exactOptionalPropertyTypes` that is otherwise a conditional spread. "No * prefix" and "absent" mean the same thing, so nothing is lost by allowing it. */ readonly prefix?: string | undefined; } /** A {@link TestClient} bound to the server `createTestServer` started. */ export declare class TestServer extends TestClient { readonly app: HttpApp; /** * Where the gateways answer, when `gatewayPort` split them off `url`. * `undefined` otherwise, which is when they are on `url` itself. */ readonly gatewayUrl: string | undefined; constructor(app: HttpApp, url: string); /** * `app.shutdown()` - stops the server, then tears the container down. An arrow, * so `afterAll(server.close)` still has its receiver. */ readonly close: () => Promise; } /** * A real `Bun.serve` on port 0, with the same override semantics as * {@link createTestApp}. `Bun.serve` binds in about a millisecond, and a fake * could only prove the parts of the request path dunx wrote rather than the parts * Bun owns - routing, params, method dispatch, upgrades. * * ```ts * const server = await createTestServer({ modules: [ApiModule], prefix: 'api' }); * const { status, body } = await server.json('api/users'); * await server.close(); * ``` * * Request logging and boot logging are off unless asked for, since a suite would * otherwise print one JSON line per assertion and one route table per file. * * An `HttpOptions` field not passed is absent, not inherited from production. * `middleware` and `onError` change what the application does, so pass the same * object `main.ts` passes. `middleware: []` says the omission is deliberate. */ export declare const createTestServer: (options: TestServerOptions) => Promise;