test(synology-chat): match request destroy typing

This commit is contained in:
bmendonca3
2026-02-27 12:20:54 -07:00
committed by Peter Steinberger
parent 6df36a8b35
commit aeeb0474c6

View File

@@ -32,21 +32,48 @@ function makeAccount(
}; };
} }
function makeStalledReq(method: string): IncomingMessage { function makeReq(method: string, body: string): IncomingMessage {
const req = new EventEmitter() as IncomingMessage & { const req = new EventEmitter() as IncomingMessage & {
destroyed: boolean; destroyed: boolean;
destroy: () => void;
}; };
req.method = method; req.method = method;
req.headers = {}; req.headers = {};
req.socket = { remoteAddress: "127.0.0.1" } as any; req.socket = { remoteAddress: "127.0.0.1" } as any;
req.destroyed = false; req.destroyed = false;
req.destroy = () => { req.destroy = ((_: Error | undefined) => {
if (req.destroyed) {
return req;
}
req.destroyed = true;
return req;
}) as IncomingMessage["destroy"];
// Simulate body delivery
process.nextTick(() => {
if (req.destroyed) { if (req.destroyed) {
return; return;
} }
req.destroyed = true; req.emit("data", Buffer.from(body));
req.emit("end");
});
return req;
}
function makeStalledReq(method: string): IncomingMessage {
const req = new EventEmitter() as IncomingMessage & {
destroyed: boolean;
}; };
req.method = method;
req.headers = {};
req.socket = { remoteAddress: "127.0.0.1" } as any;
req.destroyed = false;
req.destroy = ((_: Error | undefined) => {
if (req.destroyed) {
return req;
}
req.destroyed = true;
return req;
}) as IncomingMessage["destroy"];
return req; return req;
} }