Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ on: [push, pull_request]
jobs:
build:
name: Test
timeout-minutes: 15
uses: pkgjs/action/.github/workflows/[email protected]
with:
runs-on: ubuntu-latest, windows-latest
Expand All@@ -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]'
Expand Down
11 changes: 7 additions & 4 deletions test/balanced-pool.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand DownExpand Up@@ -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
Expand DownExpand Up@@ -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 = []

Expand DownExpand Up@@ -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'){
Expand Down
26 changes: 24 additions & 2 deletions test/fetch/abort.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -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')

Expand DownExpand Up@@ -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)
Expand All@@ -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
Expand Down