UNPKG

kequapp

Version:

DEPRECATED: renamed to @kequtech/arbor

72 lines (71 loc) 2.58 kB
/** * Unit test fakes for IncomingMessage / ServerResponse usage. * * These are intentionally minimal helpers for unit tests — they do not fully * implement node:http internals. They provide: * - header helpers * - buffering of written response bytes via `_getBuffer()`/`_getString()` * - a small set of flags (`headersSent`, `finished`, `writableEnded`, ...) * * Known deviations: * - `FakeReq` accepts `body` as a string or Buffer only. If `body` is * omitted or undefined it will be consumed and the stream closed. * - Setting `body: null` keeps the request stream open as opposed to having * to explicitly close it. * - These fakes intentionally avoid re-implementing the full Node stream * state machine or exact semantics. */ import { type OutgoingHttpHeaders } from 'node:http'; import { Transform } from 'node:stream'; import type { Header, Params, ReqOptions } from '../types.ts'; export declare class FakeReq extends Transform { [key: string]: unknown; method: string; url: string; headers: Params; rawHeaders: string[]; aborted: boolean; complete: boolean; socket: unknown; connection: unknown; trailers: Record<string, string>; rawTrailers: string[]; headersDistinct?: unknown; trailersDistinct?: unknown; constructor(options: ReqOptions); setTimeout(ms: number, cb?: () => void): this; pause(): this; resume(): this; destroy(err?: Error): this; _transform(chunk: string | Buffer, _enc: string, done: () => void): void; } export declare class FakeRes extends Transform { statusCode: number; statusMessage: string; headersSent: boolean; finished: boolean; writableEnded: boolean; writableFinished: boolean; private _headers; private _responseData; constructor(); _transform(chunk: Buffer, _enc: string, done: () => void): void; setHeader(name: string, value: Header): void; getHeader(name: string): Header; getHeaders(): OutgoingHttpHeaders; getHeaderNames(): string[]; hasHeader(name: string): boolean; removeHeader(name: string): void; addTrailers(headers: OutgoingHttpHeaders): void; flushHeaders(): void; writeHead(statusCode: number, statusMessage?: string, headers?: OutgoingHttpHeaders): void; writeContinue(): void; writeProcessing(): void; assignSocket(_socket: unknown): void; detachSocket(): void; _getBuffer(): Buffer; _getString(): string; _getJSON(): unknown; end(...args: any[]): this; setTimeout(ms: number, cb?: () => void): this; }