mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 06:22:42 +00:00
test(synology-chat): match request destroy typing
This commit is contained in:
committed by
Peter Steinberger
parent
6df36a8b35
commit
aeeb0474c6
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user