@open-draft/test-server
Version:
HTTP/HTTPS testing server for your tests.
59 lines (58 loc) • 1.94 kB
TypeScript
import { Hono } from 'hono';
import { type ServerType } from '@hono/node-server';
export type TestHttpServerProtocol = 'http' | 'https';
export interface TestHttpServer {
[Symbol.asyncDispose](): Promise<void>;
listen: (options?: ListenOptions) => Promise<void>;
close: () => Promise<void>;
http: TestHttpServerApi;
https: TestHttpServerApi;
}
export interface TestHttpServerOptions {
protocols?: Array<TestHttpServerProtocol>;
defineRoutes?: (router: Hono) => void;
}
export interface TestHttpServerApi {
url: UrlBuilderFunction;
createRoom: (options?: RoomOptions) => Room;
}
interface UrlBuilderFunction {
(pathname?: string): URL;
}
export interface RoomOptions {
defineRoutes?: (router: Hono) => void;
}
export interface ListenOptions {
hostname?: string;
}
export declare const DEFAULT_PROTOCOLS: Array<TestHttpServerProtocol>;
export declare const kApp: unique symbol;
export declare const kServer: unique symbol;
export declare const kServers: unique symbol;
export declare const kEmitter: unique symbol;
export declare function createTestHttpServer(options?: TestHttpServerOptions): TestHttpServer;
export declare function createUrlBuilder(baseUrl: string | URL, forceRelativePathname?: boolean): UrlBuilderFunction;
export declare function toRelativePathname(pathname: string): string;
export declare function getServerUrl(protocol: string, server: ServerType): URL;
declare class Room {
protected readonly options: {
roomOptions?: RoomOptions;
app: Hono;
baseUrl: URL;
};
protected id: string;
protected pathname: string;
protected router: Hono;
url: UrlBuilderFunction;
constructor(options: {
roomOptions?: RoomOptions;
app: Hono;
baseUrl: URL;
});
/**
* Close the room and remove its route handlers from the server.
*/
close(): void;
[Symbol.dispose](): void;
}
export {};