Skip to content

Commit

Permalink
test: update dns stubbing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dhensby committed Aug 3, 2023
1 parent 771e92a commit fff3b0a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions test/httpbis/httpbis.int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -100,12 +101,8 @@ function makeHttpRequest(request: Request, port?: number): Promise<http.Incoming
return new Promise<http.IncomingMessage>((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,
Expand All @@ -121,12 +118,8 @@ function makeHttp2Request(request: Request & { body?: string; }, port?: number):
return new Promise<{ headers: Record<string, string | string[]>; 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,
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit fff3b0a

Please sign in to comment.