chore: Fix types in tests 25/N.

This commit is contained in:
cpojer
2026-02-17 14:31:02 +09:00
parent 600022cdcc
commit 6e5df1dc0f
16 changed files with 118 additions and 78 deletions

View File

@@ -9,19 +9,21 @@ import {
readRequestBodyWithLimit,
} from "./http-body.js";
type MockIncomingMessage = IncomingMessage & {
destroyed?: boolean;
destroy: (error?: Error) => MockIncomingMessage;
__unhandledDestroyError?: unknown;
};
function createMockRequest(params: {
chunks?: string[];
headers?: Record<string, string>;
emitEnd?: boolean;
}): IncomingMessage {
const req = new EventEmitter() as IncomingMessage & {
destroyed?: boolean;
destroy: (error?: Error) => void;
__unhandledDestroyError?: unknown;
};
}): MockIncomingMessage {
const req = new EventEmitter() as MockIncomingMessage;
req.destroyed = false;
req.headers = params.headers ?? {};
req.destroy = (error?: Error) => {
req.destroy = ((error?: Error) => {
req.destroyed = true;
if (error) {
// Simulate Node's async 'error' emission on destroy(err). If no listener is
@@ -34,7 +36,8 @@ function createMockRequest(params: {
}
});
}
};
return req;
}) as MockIncomingMessage["destroy"];
if (params.chunks) {
void Promise.resolve().then(() => {