(url: string, noData?: boolean)
| 8 | }) |
| 9 | |
| 10 | function prime(url: string, noData?: boolean) { |
| 11 | return new Promise<void>((resolve, reject) => { |
| 12 | url = new URL(url, next.url).href |
| 13 | |
| 14 | // There's a bug in node-fetch v2 where aborting the fetch will never abort |
| 15 | // the connection, because the body is a transformed stream that doesn't |
| 16 | // close the connection stream. |
| 17 | // https://github.com/node-fetch/node-fetch/pull/670 |
| 18 | const req = get(url, async (res) => { |
| 19 | while (true) { |
| 20 | const value = res.read(1) |
| 21 | if (value) break |
| 22 | await sleep(5) |
| 23 | } |
| 24 | |
| 25 | res.destroy() |
| 26 | resolve() |
| 27 | }) |
| 28 | req.on('error', reject) |
| 29 | req.end() |
| 30 | |
| 31 | if (noData) { |
| 32 | req.on('error', (e) => { |
| 33 | // Swallow the "socket hang up" message that happens if you abort |
| 34 | // before the a response connection is received. |
| 35 | if ((e as any).code !== 'ECONNRESET') { |
| 36 | throw e |
| 37 | } |
| 38 | }) |
| 39 | |
| 40 | setTimeout(() => { |
| 41 | req.abort() |
| 42 | resolve() |
| 43 | }, 100) |
| 44 | } |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | describe.each([ |
| 49 | ['middleware', '/middleware'], |
no test coverage detected