MCPcopy Index your code
hub / github.com/callstack/agent-device / mockEventHttpRequest

Function mockEventHttpRequest

src/utils/__tests__/daemon-client.test.ts:64–100  ·  view source on GitHub ↗
(
  handler: (context: { options: Record<string, any>; body: string; res: MockHttpResponse }) => void,
)

Source from the content-addressed store, hash-verified

62}
63
64function mockEventHttpRequest(
65 handler: (context: { options: Record<string, any>; body: string; res: MockHttpResponse }) => void,
66): () => void {
67 const originalHttpRequest = http.request;
68 (http as unknown as { request: typeof http.request }).request = ((
69 options: any,
70 callback: (res: any) => void,
71 ) => {
72 const req = new EventEmitter() as EventEmitter & {
73 write: (chunk: string) => void;
74 end: () => void;
75 destroy: () => void;
76 };
77 let body = '';
78 req.write = (chunk: string) => {
79 body += chunk;
80 };
81 req.destroy = () => {
82 req.emit('close');
83 };
84 req.end = () => {
85 const res = new EventEmitter() as MockHttpResponse;
86 res.statusCode = 200;
87 res.resume = () => {};
88 res.setEncoding = () => {};
89 process.nextTick(() => {
90 callback(res);
91 handler({ options, body, res });
92 });
93 };
94 return req as any;
95 }) as typeof http.request;
96
97 return () => {
98 (http as unknown as { request: typeof http.request }).request = originalHttpRequest;
99 };
100}
101
102async function captureInteractiveStderr(callback: () => Promise<void>): Promise<string> {
103 const stderr = process.stderr as typeof process.stderr & { isTTY?: boolean };

Callers 1

Calls 1

emitMethod · 0.80

Tested by

no test coverage detected