| 19 | const writeHeadCalls: any[][] = []; |
| 20 | |
| 21 | function 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 | |
| 71 | Deno.test({ |
| 72 | name: "NodeRequest", |