diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bd8de1c3450..62f85400918 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -9,6 +9,7 @@ on: [push, pull_request] jobs: build: name: Test + timeout-minutes: 15 uses: pkgjs/action/.github/workflows/node-test.yaml@v0.1 with: runs-on: ubuntu-latest, windows-latest @@ -22,7 +23,6 @@ jobs: exclude: | - runs-on: windows-latest node-version: 16 - - node-version: 19 automerge: if: > github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' diff --git a/test/balanced-pool.js b/test/balanced-pool.js index 7e28da7c72d..be544887ef9 100644 --- a/test/balanced-pool.js +++ b/test/balanced-pool.js @@ -4,6 +4,7 @@ const { test } = require('tap') const { BalancedPool, Pool, Client, errors } = require('..') const { createServer } = require('http') const { promisify } = require('util') +const semver = require('semver') test('throws when factory is not a function', (t) => { t.plan(2) @@ -433,7 +434,10 @@ const cases = [ expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'], expectedConnectionRefusedErrors: 1, expectedSocketErrors: 0, - expectedRatios: [0.34, 0.34, 0.32] + expectedRatios: [0.34, 0.34, 0.32], + + // Skip because the behavior of Node.js has changed + skip: semver.satisfies(process.version, '>= 19.0.0') }, // 8 @@ -476,8 +480,8 @@ const cases = [ ] -for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10 }] of cases.entries()) { - test(`weighted round robin - case ${index}`, async (t) => { +for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10, only = false, skip = false }] of cases.entries()) { + test(`weighted round robin - case ${index}`, { only, skip }, async (t) => { // cerate an array to store succesfull reqeusts const requestLog = [] @@ -512,7 +516,6 @@ for (const [index, { config, expected, expectedRatios, iterations = 9, expectedC await client.request({ path: '/', method: 'GET' }) } catch (e) { const serverWithError = servers.find(server => server.port === e.port) || servers.find(server => server.port === e.socket.remotePort) - serverWithError.requestsCount++ if (e.code === 'ECONNREFUSED') { diff --git a/test/fetch/abort.js b/test/fetch/abort.js index 03ee3b44ab2..1b9f1e68e8d 100644 --- a/test/fetch/abort.js +++ b/test/fetch/abort.js @@ -5,6 +5,7 @@ const { fetch } = require('../..') const { createServer } = require('http') const { once } = require('events') const { DOMException } = require('../../lib/fetch/constants') +const semver = require('semver') const { AbortController: NPMAbortController } = require('abort-controller') @@ -36,13 +37,13 @@ test('Allow the usage of custom implementation of AbortController', async (t) => } }) -test('allows aborting with custom errors', { skip: process.version.startsWith('v16.') }, async (t) => { +test('allows aborting with custom errors', { skip: semver.satisfies(process.version, '16.x') }, async (t) => { const server = createServer().listen(0) t.teardown(server.close.bind(server)) await once(server, 'listening') - t.test('Using AbortSignal.timeout', async (t) => { + t.test('Using AbortSignal.timeout without cause', { skip: semver.satisfies(process.version, '>= 19.0.0') }, async (t) => { await t.rejects( fetch(`http://localhost:${server.address().port}`, { signal: AbortSignal.timeout(50) @@ -54,6 +55,27 @@ test('allows aborting with custom errors', { skip: process.version.startsWith('v ) }) + t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0') }, async (t) => { + t.plan(2) + + try { + await fetch(`http://localhost:${server.address().port}`, { + signal: AbortSignal.timeout(50) + }) + } catch (err) { + if (err.name === 'TypeError') { + const cause = err.cause + t.equal(cause.name, 'HeadersTimeoutError') + t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT') + } else if (err.name === 'TimeoutError') { + t.equal(err.code, DOMException.TIMEOUT_ERR) + t.equal(err.cause, undefined) + } else { + t.error(err) + } + } + }) + t.test('Error defaults to an AbortError DOMException', async (t) => { const ac = new AbortController() ac.abort() // no reason