From 4850be6f74bb33969dc19a429eda1495a2052bca Mon Sep 17 00:00:00 2001 From: Luca Del Puppo Date: Sun, 2 Aug 2026 15:40:16 +0000 Subject: [PATCH] test: drop undici, use a small node:http(s) helper undici@8.x requires Node.js >=22.10 (it uses worker_threads.markAsUncloneable, added in 22.10.0), which breaks the test suite on Node 20 (see dependabot PRs #112, #116, #118, #121, #122). The package only uses undici as a test HTTP client - nothing in the runtime depends on it - so the dependency is removed entirely. A small test/helpers/request.js wrapper around node:http and node:https keeps the existing test code shape (request(url) -> res.body.json()) and scopes self-signed-cert acceptance to the HTTPS path via a per-request https.Agent({ rejectUnauthorized: false }), with no process-level side effects. --- package.json | 3 +-- test/helpers/request.js | 41 +++++++++++++++++++++++++++++++++++++++++ test/index.test.js | 10 +--------- 3 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 test/helpers/request.js diff --git a/package.json b/package.json index 4bd7374..84e54a1 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,7 @@ "eslint": "^9.17.0", "neostandard": "^0.13.0", "split2": "^4.2.0", - "tstyche": "^7.0.0", - "undici": "^7.0.0" + "tstyche": "^7.0.0" }, "dependencies": { "fastify": "^5.0.0" diff --git a/test/helpers/request.js b/test/helpers/request.js new file mode 100644 index 0000000..5ff2dbc --- /dev/null +++ b/test/helpers/request.js @@ -0,0 +1,41 @@ +'use strict' + +const http = require('node:http') +const https = require('node:https') + +// Minimal undici-compatible `request()` built on node:http / node:https. +// +// The HTTPS path attaches a dedicated https.Agent that trusts the +// self-signed certificate from test/fixtures, so no global state +// (e.g. NODE_TLS_REJECT_UNAUTHORIZED) leaks into the test process. +function request (url, opts = {}) { + return new Promise((resolve, reject) => { + const isHttps = url.startsWith('https://') + const lib = isHttps ? https : http + + const finalOpts = { ...opts } + if (isHttps && !finalOpts.agent) { + finalOpts.agent = new https.Agent({ rejectUnauthorized: false }) + } + + const req = lib.request(url, finalOpts, (res) => { + const chunks = [] + res.on('data', (chunk) => chunks.push(chunk)) + res.on('end', () => { + const body = Buffer.concat(chunks).toString('utf8') + resolve({ + statusCode: res.statusCode, + headers: res.headers, + body: { + json: async () => JSON.parse(body), + text: async () => body + } + }) + }) + }) + req.on('error', reject) + req.end() + }) +} + +module.exports = { request } diff --git a/test/index.test.js b/test/index.test.js index 9c91224..7563600 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -7,18 +7,10 @@ const http2 = require('node:http2') const { afterEach, test } = require('node:test') const split = require('split2') -const { request, setGlobalDispatcher, Agent } = require('undici') +const { request } = require('./helpers/request') const { restartable } = require('..') -setGlobalDispatcher(new Agent({ - keepAliveTimeout: 1, - keepAliveMaxTimeout: 1, - tls: { - rejectUnauthorized: false - } -})) - const COMMON_PORT = 4242 afterEach(async () => {