MCPcopy Index your code
hub / github.com/oakserver/oak / createMockReqRes

Function createMockReqRes

http_server_node.test.ts:21–69  ·  view source on GitHub ↗
(
  url = "/",
  headers: Record<string, string> = {},
  method = "GET",
  address = "127.0.0.1",
)

Source from the content-addressed store, hash-verified

19const writeHeadCalls: any[][] = [];
20
21function createMockReqRes(
22 url = "/",
23 headers: Record<string, string> = {},
24 method = "GET",
25 address = "127.0.0.1",
26): [req: IncomingMessage, res: ServerResponse] {
27 destroyCalls.length = 0;
28 setHeaderCalls.length = 0;
29 writeCalls.length = 0;
30 writeHeadCalls.length = 0;
31 const req = {
32 headers,
33 method,
34 socket: {
35 address() {
36 return {
37 addr: {
38 address,
39 },
40 };
41 },
42 },
43 url,
44 on(_method: string, _listener: (arg?: any) => void) {},
45 };
46 const res = {
47 destroy(...args: any[]) {
48 destroyCalls.push(args);
49 },
50 end(callback?: () => void) {
51 if (callback) {
52 callback();
53 }
54 },
55 setHeader(...args: any[]) {
56 setHeaderCalls.push(args);
57 },
58 write(chunk: unknown, callback?: (err: Error | null) => void) {
59 writeCalls.push([chunk, callback]);
60 if (callback) {
61 callback(null);
62 }
63 },
64 writeHead(...args: any[]) {
65 writeHeadCalls.push(args);
66 },
67 };
68 return [req, res];
69}
70
71Deno.test({
72 name: "NodeRequest",

Callers 1

fnFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected