( tOrOptions?: ExecutionContext | HttpServerOptions, options?: HttpServerOptions, )
| 19 | export async function createHttpTestServer(t: ExecutionContext, options?: HttpServerOptions): Promise<ExtendedHttpTestServer>; |
| 20 | export async function createHttpTestServer(options?: HttpServerOptions): Promise<ExtendedHttpTestServer>; |
| 21 | export async function createHttpTestServer( |
| 22 | tOrOptions?: ExecutionContext | HttpServerOptions, |
| 23 | options?: HttpServerOptions, |
| 24 | ): Promise<ExtendedHttpTestServer> { |
| 25 | const isExecutionContext = typeof (tOrOptions as ExecutionContext)?.teardown === 'function'; |
| 26 | const t = isExecutionContext ? tOrOptions as ExecutionContext : undefined; |
| 27 | const resolvedOptions = (isExecutionContext ? options : tOrOptions as HttpServerOptions) ?? {}; |
| 28 | |
| 29 | const server = express() as ExtendedHttpTestServer; |
| 30 | server.http = http.createServer(server); |
| 31 | |
| 32 | server.set('etag', false); |
| 33 | server.http.keepAliveTimeout = 0; |
| 34 | server.http.unref(); |
| 35 | |
| 36 | if (resolvedOptions.bodyParser !== false) { |
| 37 | server.use(express.json({limit: '1mb', type: 'application/json'})); |
| 38 | server.use(express.text({limit: '1mb', type: 'text/plain'})); |
| 39 | server.use(express.urlencoded({limit: '1mb', type: 'application/x-www-form-urlencoded', extended: true})); |
| 40 | server.use(express.raw({limit: '1mb', type: 'application/octet-stream'})); |
| 41 | } |
| 42 | |
| 43 | await promisify(server.http.listen.bind(server.http))(); |
| 44 | |
| 45 | server.port = (server.http.address() as net.AddressInfo).port; |
| 46 | server.url = `http://localhost:${server.port}`; |
| 47 | server.hostname = 'localhost'; |
| 48 | |
| 49 | server.close = async () => { |
| 50 | server.http.closeAllConnections(); |
| 51 | await promisify(server.http.close.bind(server.http))(); |
| 52 | }; |
| 53 | |
| 54 | if (t) { |
| 55 | t.teardown(server.close); |
| 56 | } |
| 57 | |
| 58 | return server; |
| 59 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…