mirror of
https://github.com/hanzoai/bot.git
synced 2026-10-30 17:24:26 +00:00
- Run oxfmt --write to fix 765 files with formatting drift - Fix no-redundant-type-constituents in secrets/runtime.ts (SecretDefaults resolves to any, making | undefined redundant) - Fix no-redundant-type-constituents in plugin hook test files (error types resolve to any, simplify return types)
28 lines
652 B
TypeScript
28 lines
652 B
TypeScript
import type { IncomingMessage } from "node:http";
|
|
import { EventEmitter } from "node:events";
|
|
|
|
export function createMockIncomingRequest(chunks: string[]): IncomingMessage {
|
|
const req = new EventEmitter() as IncomingMessage & {
|
|
destroyed?: boolean;
|
|
destroy: (error?: Error) => IncomingMessage;
|
|
};
|
|
req.destroyed = false;
|
|
req.headers = {};
|
|
req.destroy = () => {
|
|
req.destroyed = true;
|
|
return req;
|
|
};
|
|
|
|
void Promise.resolve().then(() => {
|
|
for (const chunk of chunks) {
|
|
req.emit("data", Buffer.from(chunk, "utf-8"));
|
|
if (req.destroyed) {
|
|
return;
|
|
}
|
|
}
|
|
req.emit("end");
|
|
});
|
|
|
|
return req;
|
|
}
|