diff --git a/test/fetch/client-node-max-header-size.js b/test/fetch/client-node-max-header-size.js index d044731cf95..9906c7e8b81 100644 --- a/test/fetch/client-node-max-header-size.js +++ b/test/fetch/client-node-max-header-size.js @@ -1,21 +1,25 @@ 'use strict' -const { execSync } = require('node:child_process') +const { tspl } = require('@matteo.collina/tspl') +const { exec } = require('node:child_process') const { test } = require('node:test') -const assert = require('node:assert') const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin.org/get\')"' -test("respect Node.js' --max-http-header-size", async () => { - assert.throws( - () => execSync(`${command} --max-http-header-size=1`), - /UND_ERR_HEADERS_OVERFLOW/, - 'max-http-header-size=1 should throw' - ) +test("respect Node.js' --max-http-header-size", async (t) => { + t = tspl(t, { plan: 6 }) - assert.doesNotThrow( - () => execSync(command), - /UND_ERR_HEADERS_OVERFLOW/, - 'default max-http-header-size should not throw' - ) + exec(`${command} --max-http-header-size=1`, { stdio: 'pipe' }, (err, stdout, stderr) => { + t.strictEqual(err.code, 1) + t.strictEqual(stdout, '') + t.match(stderr, /UND_ERR_HEADERS_OVERFLOW/, '--max-http-header-size=1 should throw') + }) + + exec(command, { stdio: 'pipe' }, (err, stdout, stderr) => { + t.ifError(err) + t.strictEqual(stdout, '') + t.strictEqual(stderr, '', 'default max-http-header-size should not throw') + }) + + await t.completed }) diff --git a/test/utils/node-http.js b/test/utils/node-http.js index c1d743a8a37..b454309b381 100644 --- a/test/utils/node-http.js +++ b/test/utils/node-http.js @@ -3,7 +3,10 @@ const util = require('node:util') function closeServerAsPromise (server) { - return () => util.promisify(server.close.bind(server))() + return () => { + server.closeIdleConnections() + return util.promisify(server.close.bind(server))() + } } function closeClientAndServerAsPromise (client, server) {