diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 0afd197845d..463a04b1dc7 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -21,6 +21,8 @@ jobs: - runs-on: ubuntu-latest node-version: 16.8 exclude: | + - runs-on: windows-latest + node-version: 14 - runs-on: windows-latest node-version: 16 automerge: diff --git a/test/autoselectfamily.js b/test/autoselectfamily.js index 6588123d2c7..aa9a751365a 100644 --- a/test/autoselectfamily.js +++ b/test/autoselectfamily.js @@ -6,10 +6,18 @@ const { Resolver } = require('dns') const dnsPacket = require('dns-packet') const { createServer } = require('http') const { Client, Agent, request } = require('..') -const { nodeHasAutoSelectFamily, nodeMajor } = require('../lib/core/util') - -if (nodeMajor >= 20) { - skip('some tests are failing') +const { nodeHasAutoSelectFamily } = require('../lib/core/util') + +/* + * IMPORTANT + * + * As only some version of Node have autoSelectFamily enabled by default (>= 20), make sure the option is always + * explicitly passed in tests in this file to avoid compatibility problems across release lines. + * + */ + +if (!nodeHasAutoSelectFamily) { + skip('autoSelectFamily is not supportee') process.exit() } @@ -59,84 +67,82 @@ function createDnsServer (ipv6Addr, ipv4Addr, cb) { }) } -if (nodeHasAutoSelectFamily) { - test('with autoSelectFamily enable the request succeeds when using request', (t) => { - t.plan(3) +test('with autoSelectFamily enable the request succeeds when using request', (t) => { + t.plan(3) - createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) { - const server = createServer((req, res) => { - res.end('hello') - }) + createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) { + const server = createServer((req, res) => { + res.end('hello') + }) - t.teardown(() => { - server.close() - dnsServer.close() - }) + t.teardown(() => { + server.close() + dnsServer.close() + }) - server.listen(0, '127.0.0.1', () => { - const agent = new Agent({ connect: { lookup }, autoSelectFamily: true }) + server.listen(0, '127.0.0.1', () => { + const agent = new Agent({ connect: { lookup }, autoSelectFamily: true }) - request( - `http://example.org:${server.address().port}/`, { - method: 'GET', - dispatcher: agent - }, (err, { statusCode, body }) => { - t.error(err) + request( + `http://example.org:${server.address().port}/`, { + method: 'GET', + dispatcher: agent + }, (err, { statusCode, body }) => { + t.error(err) - let response = Buffer.alloc(0) + let response = Buffer.alloc(0) - body.on('data', chunk => { - response = Buffer.concat([response, chunk]) - }) + body.on('data', chunk => { + response = Buffer.concat([response, chunk]) + }) - body.on('end', () => { - t.strictSame(statusCode, 200) - t.strictSame(response.toString('utf-8'), 'hello') - }) + body.on('end', () => { + t.strictSame(statusCode, 200) + t.strictSame(response.toString('utf-8'), 'hello') }) - }) + }) }) }) +}) - test('with autoSelectFamily enable the request succeeds when using a client', (t) => { - t.plan(3) +test('with autoSelectFamily enable the request succeeds when using a client', (t) => { + t.plan(3) - createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) { - const server = createServer((req, res) => { - res.end('hello') - }) + createDnsServer('::1', '127.0.0.1', function (_, { dnsServer, lookup }) { + const server = createServer((req, res) => { + res.end('hello') + }) - t.teardown(() => { - server.close() - dnsServer.close() - }) + t.teardown(() => { + server.close() + dnsServer.close() + }) - server.listen(0, '127.0.0.1', () => { - const client = new Client(`http://example.org:${server.address().port}`, { connect: { lookup }, autoSelectFamily: true }) + server.listen(0, '127.0.0.1', () => { + const client = new Client(`http://example.org:${server.address().port}`, { connect: { lookup }, autoSelectFamily: true }) - t.teardown(client.destroy.bind(client)) + t.teardown(client.destroy.bind(client)) - client.request({ - path: '/', - method: 'GET' - }, (err, { statusCode, body }) => { - t.error(err) + client.request({ + path: '/', + method: 'GET' + }, (err, { statusCode, body }) => { + t.error(err) - let response = Buffer.alloc(0) + let response = Buffer.alloc(0) - body.on('data', chunk => { - response = Buffer.concat([response, chunk]) - }) + body.on('data', chunk => { + response = Buffer.concat([response, chunk]) + }) - body.on('end', () => { - t.strictSame(statusCode, 200) - t.strictSame(response.toString('utf-8'), 'hello') - }) + body.on('end', () => { + t.strictSame(statusCode, 200) + t.strictSame(response.toString('utf-8'), 'hello') }) }) }) }) -} +}) test('with autoSelectFamily disabled the request fails when using request', (t) => { t.plan(1) @@ -152,7 +158,7 @@ test('with autoSelectFamily disabled the request fails when using request', (t) }) server.listen(0, '127.0.0.1', () => { - const agent = new Agent({ connect: { lookup } }) + const agent = new Agent({ connect: { lookup, autoSelectFamily: false } }) request(`http://example.org:${server.address().port}`, { method: 'GET', @@ -178,7 +184,7 @@ test('with autoSelectFamily disabled the request fails when using a client', (t) }) server.listen(0, '127.0.0.1', () => { - const client = new Client(`http://example.org:${server.address().port}`, { connect: { lookup } }) + const client = new Client(`http://example.org:${server.address().port}`, { connect: { lookup, autoSelectFamily: false } }) t.teardown(client.destroy.bind(client)) client.request({