()
| 52 | * Creates a test server. |
| 53 | */ |
| 54 | export function createTestServer(): http.Server { |
| 55 | return http.createServer(function (req, res) { |
| 56 | if (req.url?.endsWith('/connection_timeout')) { |
| 57 | setTimeout(() => { |
| 58 | res.writeHead(200, { |
| 59 | 'content-type': 'text/plain', |
| 60 | 'access-control-allow-origin': '*', |
| 61 | 'x-powered-by': 'nodejs', |
| 62 | }); |
| 63 | |
| 64 | res.write('{"foo": "bar"}'); |
| 65 | res.end(); |
| 66 | }, 5000); |
| 67 | } else if (req.url?.endsWith('/response_stream_error')) { |
| 68 | // Send headers + partial body, then destroy the socket. |
| 69 | // This triggers response.on('error') on the client side (typically ECONNRESET). |
| 70 | res.writeHead(200, { |
| 71 | 'content-type': 'text/plain', |
| 72 | 'access-control-allow-origin': '*', |
| 73 | }); |
| 74 | res.write('partial'); |
| 75 | setTimeout(() => { |
| 76 | req.socket.destroy(); |
| 77 | }, 50); |
| 78 | } else { |
| 79 | res.writeHead(200, { |
| 80 | 'content-type': 'text/plain', |
| 81 | 'access-control-allow-origin': '*', |
| 82 | 'x-powered-by': 'nodejs', |
| 83 | }); |
| 84 | |
| 85 | res.write('{"foo":'); |
| 86 | |
| 87 | setTimeout(() => { |
| 88 | res.write(' "bar"'); |
| 89 | }, 1000); |
| 90 | |
| 91 | setTimeout(() => { |
| 92 | res.write('}'); |
| 93 | res.end(); |
| 94 | }, 5000); |
| 95 | } |
| 96 | }); |
| 97 | } |
no outgoing calls
no test coverage detected