Skip to content

Commit 00f999d

Browse files
authored
refactor: version cleanup (#2605)
* refactor: version cleanup * remove skip * remove comment * remove ` --unhandled-rejections=throw`
1 parent 887d1cb commit 00f999d

7 files changed

+11
-29
lines changed

lib/core/util.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,8 @@ function validateHandler (handler, method, upgrade) {
349349
// A body is disturbed if it has been read from and it cannot
350350
// be re-used without losing state or data.
351351
function isDisturbed (body) {
352-
return !!(body && (
353-
stream.isDisturbed
354-
? stream.isDisturbed(body) || body[kBodyUsed] // TODO (fix): Why is body[kBodyUsed] needed?
355-
: body[kBodyUsed] ||
356-
body.readableDidRead ||
357-
(body._readableState && body._readableState.dataEmitted) ||
358-
isReadableAborted(body)
359-
))
352+
// TODO (fix): Why is body[kBodyUsed] needed?
353+
return !!(body && (stream.isDisturbed(body) || body[kBodyUsed]))
360354
}
361355

362356
function isErrored (body) {

lib/fetch/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,6 @@ function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis,
327327

328328
// https://fetch.spec.whatwg.org/#abort-fetch
329329
function abortFetch (p, request, responseObject, error) {
330-
// Note: AbortSignal.reason was added in node v17.2.0
331-
// which would give us an undefined error to reject with.
332-
// Remove this once node v16 is no longer supported.
333-
if (!error) {
334-
error = new DOMException('The operation was aborted.', 'AbortError')
335-
}
336-
337330
// 1. Reject promise with error.
338331
p.reject(error)
339332

test/client-node-max-header-size.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const command = 'node -e "require(\'.\').request(\'https://httpbin.org/get\')"'
77

88
test("respect Node.js' --max-http-header-size", async (t) => {
99
t.throws(
10-
// TODO: Drop the `--unhandled-rejections=throw` once we drop Node.js 14
11-
() => execSync(`${command} --max-http-header-size=1 --unhandled-rejections=throw`),
10+
() => execSync(`${command} --max-http-header-size=1`),
1211
/UND_ERR_HEADERS_OVERFLOW/,
1312
'max-http-header-size=1 should throw'
1413
)

test/fetch/client-node-max-header-size.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ const command = 'node -e "require(\'./undici-fetch.js\').fetch(\'https://httpbin
88

99
test("respect Node.js' --max-http-header-size", async () => {
1010
assert.throws(
11-
// TODO: Drop the `--unhandled-rejections=throw` once we drop Node.js 14
12-
() => execSync(`${command} --max-http-header-size=1 --unhandled-rejections=throw`),
11+
() => execSync(`${command} --max-http-header-size=1`),
1312
/UND_ERR_HEADERS_OVERFLOW/,
1413
'max-http-header-size=1 should throw'
1514
)

test/fetch/response.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ test('Modifying headers using Headers.prototype.set', () => {
165165
})
166166

167167
// https://github.com/nodejs/node/issues/43838
168-
test('constructing a Response with a ReadableStream body', { skip: process.version.startsWith('v16.') }, async (t) => {
168+
test('constructing a Response with a ReadableStream body', async (t) => {
169169
const text = '{"foo":"bar"}'
170170
const uint8 = new TextEncoder().encode(text)
171171

@@ -199,7 +199,7 @@ test('constructing a Response with a ReadableStream body', { skip: process.versi
199199
await assert.rejects(response.text(), TypeError)
200200
})
201201

202-
await t.test('Readable with ArrayBuffer chunk still throws', { skip: process.version.startsWith('v16.') }, async () => {
202+
await t.test('Readable with ArrayBuffer chunk still throws', async () => {
203203
const readable = new ReadableStream({
204204
start (controller) {
205205
controller.enqueue(uint8.buffer)
@@ -210,14 +210,12 @@ test('constructing a Response with a ReadableStream body', { skip: process.versi
210210
const response1 = new Response(readable)
211211
const response2 = response1.clone()
212212
const response3 = response1.clone()
213-
// const response4 = response1.clone()
213+
const response4 = response1.clone()
214214

215215
await assert.rejects(response1.arrayBuffer(), TypeError)
216216
await assert.rejects(response2.text(), TypeError)
217217
await assert.rejects(response3.json(), TypeError)
218-
// TODO: on Node v16.8.0, this throws a TypeError
219-
// because the body is detected as disturbed.
220-
// await t.rejects(response4.blob(), TypeError)
218+
await assert.rejects(response4.blob(), TypeError)
221219
})
222220
})
223221

types/dispatcher.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ declare namespace Dispatcher {
229229
* @link https://fetch.spec.whatwg.org/#body-mixin
230230
*/
231231
interface BodyMixin {
232-
readonly body?: never; // throws on node v16.6.0
232+
readonly body?: never;
233233
readonly bodyUsed: boolean;
234234
arrayBuffer(): Promise<ArrayBuffer>;
235235
blob(): Promise<Blob>;

types/readable.d.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ declare class BodyReadable extends Readable {
4444
*/
4545
readonly bodyUsed: boolean
4646

47-
/** Throws on node 16.6.0
48-
*
49-
* If body is null, it should return null as the body
47+
/**
48+
* If body is null, it should return null as the body
5049
*
5150
* If body is not null, should return the body as a ReadableStream
5251
*

0 commit comments

Comments
 (0)