Skip to content

Commit 47f574d

Browse files
authored
Make test pass in v19.x (#1879)
* Make test pass in v19.x Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * enable v19 Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * github CI timeout Signed-off-by: Matteo Collina <hello@matteocollina.com> Signed-off-by: Matteo Collina <hello@matteocollina.com>
1 parent 25a8aac commit 47f574d

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on: [push, pull_request]
99
jobs:
1010
build:
1111
name: Test
12+
timeout-minutes: 15
1213
uses: pkgjs/action/.github/workflows/node-test.yaml@v0.1
1314
with:
1415
runs-on: ubuntu-latest, windows-latest
@@ -22,7 +23,6 @@ jobs:
2223
exclude: |
2324
- runs-on: windows-latest
2425
node-version: 16
25-
- node-version: 19
2626
automerge:
2727
if: >
2828
github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]'

test/balanced-pool.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const { test } = require('tap')
44
const { BalancedPool, Pool, Client, errors } = require('..')
55
const { createServer } = require('http')
66
const { promisify } = require('util')
7+
const semver = require('semver')
78

89
test('throws when factory is not a function', (t) => {
910
t.plan(2)
@@ -433,7 +434,10 @@ const cases = [
433434
expected: ['A', 'B', 'C', 'A', 'B', 'C/connectionRefused', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'],
434435
expectedConnectionRefusedErrors: 1,
435436
expectedSocketErrors: 0,
436-
expectedRatios: [0.34, 0.34, 0.32]
437+
expectedRatios: [0.34, 0.34, 0.32],
438+
439+
// Skip because the behavior of Node.js has changed
440+
skip: semver.satisfies(process.version, '>= 19.0.0')
437441
},
438442

439443
// 8
@@ -476,8 +480,8 @@ const cases = [
476480

477481
]
478482

479-
for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10 }] of cases.entries()) {
480-
test(`weighted round robin - case ${index}`, async (t) => {
483+
for (const [index, { config, expected, expectedRatios, iterations = 9, expectedConnectionRefusedErrors = 0, expectedSocketErrors = 0, maxWeightPerServer, errorPenalty = 10, only = false, skip = false }] of cases.entries()) {
484+
test(`weighted round robin - case ${index}`, { only, skip }, async (t) => {
481485
// cerate an array to store succesfull reqeusts
482486
const requestLog = []
483487

@@ -512,7 +516,6 @@ for (const [index, { config, expected, expectedRatios, iterations = 9, expectedC
512516
await client.request({ path: '/', method: 'GET' })
513517
} catch (e) {
514518
const serverWithError = servers.find(server => server.port === e.port) || servers.find(server => server.port === e.socket.remotePort)
515-
516519
serverWithError.requestsCount++
517520

518521
if (e.code === 'ECONNREFUSED') {

test/fetch/abort.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { fetch } = require('../..')
55
const { createServer } = require('http')
66
const { once } = require('events')
77
const { DOMException } = require('../../lib/fetch/constants')
8+
const semver = require('semver')
89

910
const { AbortController: NPMAbortController } = require('abort-controller')
1011

@@ -36,13 +37,13 @@ test('Allow the usage of custom implementation of AbortController', async (t) =>
3637
}
3738
})
3839

39-
test('allows aborting with custom errors', { skip: process.version.startsWith('v16.') }, async (t) => {
40+
test('allows aborting with custom errors', { skip: semver.satisfies(process.version, '16.x') }, async (t) => {
4041
const server = createServer().listen(0)
4142

4243
t.teardown(server.close.bind(server))
4344
await once(server, 'listening')
4445

45-
t.test('Using AbortSignal.timeout', async (t) => {
46+
t.test('Using AbortSignal.timeout without cause', { skip: semver.satisfies(process.version, '>= 19.0.0') }, async (t) => {
4647
await t.rejects(
4748
fetch(`http://localhost:${server.address().port}`, {
4849
signal: AbortSignal.timeout(50)
@@ -54,6 +55,27 @@ test('allows aborting with custom errors', { skip: process.version.startsWith('v
5455
)
5556
})
5657

58+
t.test('Using AbortSignal.timeout with cause', { skip: semver.satisfies(process.version, '< 19.0.0') }, async (t) => {
59+
t.plan(2)
60+
61+
try {
62+
await fetch(`http://localhost:${server.address().port}`, {
63+
signal: AbortSignal.timeout(50)
64+
})
65+
} catch (err) {
66+
if (err.name === 'TypeError') {
67+
const cause = err.cause
68+
t.equal(cause.name, 'HeadersTimeoutError')
69+
t.equal(cause.code, 'UND_ERR_HEADERS_TIMEOUT')
70+
} else if (err.name === 'TimeoutError') {
71+
t.equal(err.code, DOMException.TIMEOUT_ERR)
72+
t.equal(err.cause, undefined)
73+
} else {
74+
t.error(err)
75+
}
76+
}
77+
})
78+
5779
t.test('Error defaults to an AbortError DOMException', async (t) => {
5880
const ac = new AbortController()
5981
ac.abort() // no reason

0 commit comments

Comments
 (0)