From fff3b0a0e2fcb34e821a567f6c39d52ac1315fa8 Mon Sep 17 00:00:00 2001 From: Dan Hensby Date: Thu, 3 Aug 2023 12:02:16 +0200 Subject: [PATCH] test: update dns stubbing in tests --- test/httpbis/httpbis.int.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/httpbis/httpbis.int.ts b/test/httpbis/httpbis.int.ts index 5437bcc..3651a4b 100644 --- a/test/httpbis/httpbis.int.ts +++ b/test/httpbis/httpbis.int.ts @@ -12,6 +12,7 @@ import { import { promises as fs } from 'fs'; import { parse } from 'path'; import { stub } from 'sinon'; +import { lookup, LookupOneOptions } from 'dns'; interface ServerConfig { port: number; @@ -100,12 +101,8 @@ function makeHttpRequest(request: Request, port?: number): Promise((resolve, reject) => { const url = typeof request.url === 'string' ? new URL(request.url) : request.url; const req = http.request({ - lookup: (hostname, options, callback) => { - if (options.family === 6) { - callback(null, '::1', 6); - } else { - callback(null, '127.0.0.1', 4); - } + lookup: (hostname: string, options: LookupOneOptions, callback) => { + lookup('localhost', options, callback); }, hostname: url.hostname, port: port ?? url.port ?? 80, @@ -121,12 +118,8 @@ function makeHttp2Request(request: Request & { body?: string; }, port?: number): return new Promise<{ headers: Record; body: Buffer; }>((resolve, reject) => { const url = typeof request.url === 'string' ? new URL(request.url) : request.url; const client = http2.connect(request.url, { - lookup: (hostname, options, callback) => { - if (options.family === 6) { - callback(null, '::1', 6); - } else { - callback(null, '127.0.0.1', 4); - } + lookup: (hostname: string, options: LookupOneOptions, callback) => { + lookup('localhost', options, callback); }, // host: url.host, port: port ?? parseInt(url.port, 10) ?? 80, @@ -198,7 +191,8 @@ describe('httpbis', () => { return server.start(); }); beforeEach('reset requests', () => server.clear()); - after('stop server', async () => { + after('stop server', async function stopServer () { + this.timeout(5000); return server.stop(); }); describe('rsa-pss-sha512', () => {