()
| 81 | }); |
| 82 | |
| 83 | export async function startLocalServer() { |
| 84 | if (localServer) { |
| 85 | const address = localServer.address() as AddressInfo; |
| 86 | return `http://127.0.0.1:${address.port}`; |
| 87 | } |
| 88 | |
| 89 | let retry = false; |
| 90 | const app = new Koa(); |
| 91 | app.use(async ctx => { |
| 92 | if (ctx.path === '/get_headers') { |
| 93 | ctx.body = ctx.request.headers; |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | if (ctx.path === '/timeout') { |
| 98 | await scheduler.wait(10000); |
| 99 | ctx.body = `${ctx.method} ${ctx.path}`; |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | if (ctx.path === '/error') { |
| 104 | ctx.status = 500; |
| 105 | ctx.body = 'this is an error'; |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (ctx.path === '/retry') { |
| 110 | if (!retry) { |
| 111 | retry = true; |
| 112 | ctx.status = 500; |
| 113 | } else { |
| 114 | ctx.set('x-retry', '1'); |
| 115 | ctx.body = 'retry suc'; |
| 116 | retry = false; |
| 117 | } |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | ctx.body = `${ctx.method} ${ctx.path}`; |
| 122 | }); |
| 123 | localServer = http.createServer(app.callback()); |
| 124 | localServer.listen(0); |
| 125 | await once(localServer, 'listening'); |
| 126 | const address = localServer!.address() as AddressInfo; |
| 127 | return `http://127.0.0.1:${address.port}`; |
| 128 | } |
| 129 | |
| 130 | export function getFilepath(name: string) { |
| 131 | return path.join(fixtures, name); |
no test coverage detected
searching dependent graphs…