Skip to content

Commit b44f180

Browse files
committed
Drop test Node <16 workarounds & simplify version checks
1 parent 52bfe2c commit b44f180

File tree

10 files changed

+34
-86
lines changed

10 files changed

+34
-86
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
"karma-spec-reporter": "0.0.32",
135135
"karma-webpack": "^5.0.0",
136136
"mocha": "^9.1.3",
137-
"node-abort-controller": "^3.0.1",
138137
"opn": "^5.1.0",
139138
"path-browserify": "^1.0.1",
140139
"process": "^0.11.10",

test/integration/form-data.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import * as semver from 'semver';
2-
31
import { getLocal } from "../..";
42
import {
53
expect,
64
File,
75
fetch as fetchPolyfill,
8-
NATIVE_FETCH_SUPPORTED
6+
NATIVE_FETCH_SUPPORTED,
7+
nodeSatisfies
98
} from "../test-utils";
109

1110
const fetch = globalThis.fetch ?? fetchPolyfill;
@@ -66,7 +65,7 @@ describe("Body getXFormData methods", () => {
6665
describe("given multipart/form-data", () => {
6766
before(function () {
6867
// Polyfill fetch encodes polyfill FormData into "[object FormData]", which is not parsable
69-
if (process.version && !semver.satisfies(process.version, NATIVE_FETCH_SUPPORTED)) this.skip();
68+
if (!nodeSatisfies(NATIVE_FETCH_SUPPORTED)) this.skip();
7069
});
7170

7271
it("should automatically parse as form data", async () => {

test/integration/handlers/broken-response.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as semver from 'semver';
21
import * as http from 'http';
32

43
import { getLocal } from "../../..";
@@ -8,9 +7,10 @@ import {
87
isNode,
98
nodeOnly,
109
delay,
11-
SOCKET_RESET_SUPPORTED,
1210
openRawTlsSocket,
1311
http2ProxyRequest,
12+
nodeSatisfies,
13+
SOCKET_RESET_SUPPORTED,
1414
BROKEN_H1_OVER_H2_TUNNELLING
1515
} from "../../test-utils";
1616

@@ -33,7 +33,7 @@ describe("Broken response handlers", function () {
3333
});
3434

3535
it("should allow forcibly resetting the connection", async function () {
36-
if (!semver.satisfies(process.version, SOCKET_RESET_SUPPORTED)) this.skip();
36+
if (!nodeSatisfies(SOCKET_RESET_SUPPORTED)) this.skip();
3737

3838
await server.forGet('/mocked-endpoint').thenResetConnection();
3939

@@ -71,7 +71,7 @@ describe("Broken response handlers", function () {
7171

7272
nodeOnly(() => {
7373
it("should allow forcibly closing proxied connections", async function () {
74-
if (!semver.satisfies(process.version, SOCKET_RESET_SUPPORTED)) this.skip();
74+
if (!nodeSatisfies(SOCKET_RESET_SUPPORTED)) this.skip();
7575

7676
await server.forGet('example.com').thenResetConnection();
7777

@@ -93,7 +93,7 @@ describe("Broken response handlers", function () {
9393
});
9494

9595
it("should allow forcibly closing h2-over-h2 proxy connections", async function () {
96-
if (!semver.satisfies(process.version, SOCKET_RESET_SUPPORTED)) this.skip();
96+
if (!nodeSatisfies(SOCKET_RESET_SUPPORTED)) this.skip();
9797

9898
await server.forGet('example.com').thenResetConnection();
9999

@@ -107,8 +107,8 @@ describe("Broken response handlers", function () {
107107
});
108108

109109
it("should allow forcibly closing h1.1-over-h2 proxy connections", async function () {
110-
if (!semver.satisfies(process.version, SOCKET_RESET_SUPPORTED)) this.skip();
111-
if (semver.satisfies(process.version, BROKEN_H1_OVER_H2_TUNNELLING)) this.skip();
110+
if (!nodeSatisfies(SOCKET_RESET_SUPPORTED)) this.skip();
111+
if (nodeSatisfies(BROKEN_H1_OVER_H2_TUNNELLING)) this.skip();
112112

113113
await server.forGet('example.com').thenResetConnection();
114114

test/integration/http2.spec.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as tls from 'tls';
44
import * as http from 'http';
55
import * as https from 'https';
66
import * as http2 from 'http2';
7-
import * as semver from 'semver';
87
import * as fs from 'fs';
98
import * as portfinder from 'portfinder';
109

@@ -18,9 +17,9 @@ import {
1817
makeDestroyable,
1918
cleanup,
2019
fetch,
21-
H2_TLS_ON_TLS_SUPPORTED,
2220
BROKEN_H2_OVER_H2_TUNNELLING,
23-
getDeferred
21+
getDeferred,
22+
nodeSatisfies
2423
} from "../test-utils";
2524

2625
browserOnly(() => {
@@ -80,7 +79,7 @@ nodeOnly(() => {
8079

8180
describe("without TLS", function () {
8281

83-
if (semver.satisfies(process.version, BROKEN_H2_OVER_H2_TUNNELLING)) return;
82+
if (nodeSatisfies(BROKEN_H2_OVER_H2_TUNNELLING)) return;
8483

8584
const server = getLocal();
8685

@@ -375,8 +374,6 @@ nodeOnly(() => {
375374
});
376375

377376
it("can respond to proxied HTTP/2 requests", async function() {
378-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
379-
380377
await server.forGet('https://example.com/mocked-endpoint')
381378
.thenReply(200, "Proxied HTTP2 response!");
382379

@@ -413,8 +410,6 @@ nodeOnly(() => {
413410
});
414411

415412
it("should include request metadata in events for proxied HTTP/2 requests", async function() {
416-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
417-
418413
let seenRequestPromise = getDeferred<CompletedRequest>();
419414
await server.on('request', (r) => seenRequestPromise.resolve(r));
420415

@@ -462,8 +457,6 @@ nodeOnly(() => {
462457
});
463458

464459
it("should include response metadata in events for proxied HTTP/2 responses", async function() {
465-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
466-
467460
let seenResponsePromise = getDeferred<CompletedResponse>();
468461
await server.on('response', (r) => seenResponsePromise.resolve(r));
469462

@@ -515,8 +508,6 @@ nodeOnly(() => {
515508
});
516509

517510
it("can respond to HTTP1-proxied HTTP/2 requests", async function() {
518-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
519-
520511
await server.forGet('https://example.com/mocked-endpoint')
521512
.thenReply(200, "Proxied HTTP2 response!");
522513

@@ -579,8 +570,6 @@ nodeOnly(() => {
579570
afterEach(() => http2Server.destroy());
580571

581572
it("can pass through end-to-end HTTP/2", async function () {
582-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
583-
584573
await server.forGet(`https://localhost:${targetPort}/`)
585574
.thenPassThrough({ ignoreHostHttpsErrors: ['localhost'] });
586575

test/integration/https.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import * as http from 'http';
22
import * as tls from 'tls';
33
import * as https from 'https';
44
import * as fs from 'fs/promises';
5-
import * as semver from 'semver';
65

76
import { getLocal } from "../..";
87
import {
@@ -13,6 +12,7 @@ import {
1312
openRawSocket,
1413
openRawTlsSocket,
1514
http2ProxyRequest,
15+
nodeSatisfies,
1616
DETAILED_TLS_ERROR_CODES
1717
} from "../test-utils";
1818
import { streamToBuffer } from '../../src/util/buffer-utils';
@@ -462,7 +462,7 @@ describe("When configured for HTTPS", () => {
462462
throw new Error('Expected connection to fail');
463463
} catch (e: any) {
464464
expect(e.code).to.equal(
465-
semver.satisfies(process.version, DETAILED_TLS_ERROR_CODES)
465+
nodeSatisfies(DETAILED_TLS_ERROR_CODES)
466466
? 'ERR_SSL_TLSV1_ALERT_PROTOCOL_VERSION'
467467
: 'ECONNRESET'
468468
);
@@ -479,7 +479,7 @@ describe("When configured for HTTPS", () => {
479479
throw new Error('Expected connection to fail');
480480
} catch (e: any) {
481481
expect(e.code).to.equal(
482-
semver.satisfies(process.version, DETAILED_TLS_ERROR_CODES)
482+
nodeSatisfies(DETAILED_TLS_ERROR_CODES)
483483
? 'ERR_SSL_TLSV1_ALERT_PROTOCOL_VERSION'
484484
: 'ECONNRESET'
485485
);

test/integration/proxying/https-proxying.spec.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import _ = require("lodash");
22
import * as https from 'https';
33
import * as http2 from 'http2';
44
import * as fs from 'fs/promises';
5-
import * as semver from 'semver';
65
import portfinder = require('portfinder');
76
import request = require("request-promise-native");
87
import * as zlib from 'zlib';
@@ -15,8 +14,8 @@ import {
1514
http2ProxyRequest,
1615
makeDestroyable,
1716
DestroyableServer,
18-
H2_TLS_ON_TLS_SUPPORTED,
1917
ignoreNetworkError,
18+
nodeSatisfies,
2019
SOCKET_RESET_SUPPORTED
2120
} from "../../test-utils";
2221
import { CA } from "../../../src/util/tls";
@@ -369,7 +368,7 @@ nodeOnly(() => {
369368
}).catch(e => e);
370369

371370
expect(result).to.be.instanceof(Error);
372-
if (semver.satisfies(process.version, SOCKET_RESET_SUPPORTED)) {
371+
if (nodeSatisfies(SOCKET_RESET_SUPPORTED)) {
373372
expect((result as any).message).to.include('ECONNRESET');
374373
} else {
375374
expect((result as any).message).to.include('socket hang up');
@@ -469,10 +468,6 @@ nodeOnly(() => {
469468

470469
describe("when making HTTP/2 requests", () => {
471470

472-
before(function () {
473-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
474-
});
475-
476471
let http2Server: DestroyableServer<http2.Http2SecureServer>;
477472
let targetPort: number;
478473

@@ -1089,10 +1084,6 @@ nodeOnly(() => {
10891084

10901085
describe("to an HTTP/1 server", () => {
10911086

1092-
before(function () {
1093-
if (!semver.satisfies(process.version, H2_TLS_ON_TLS_SUPPORTED)) this.skip();
1094-
});
1095-
10961087
const remoteH1Server = getLocal({
10971088
https: {
10981089
keyPath: './test/fixtures/test-ca.key',

test/integration/subscriptions/client-error-events.spec.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as _ from 'lodash';
22
import HttpsProxyAgent = require('https-proxy-agent');
3-
import * as semver from 'semver';
43

54
import { getLocal, CompletedResponse, ClientError } from "../../..";
65
import {
@@ -202,18 +201,9 @@ describe("Client error subscription", () => {
202201
expect(clientError.errorCode).to.equal("HPE_HEADER_OVERFLOW");
203202
expect(clientError.request.protocol).to.equal('https');
204203

205-
// What the parser exposes when it fails is different depending on the Node version:
206-
if (semver.satisfies(process.version, '>=13')) {
207-
// Buffer overflows completely here, so parsing sees overwritten data as the start:
208-
expect(clientError.request.method?.slice(0, 10)).to.equal('XXXXXXXXXX');
209-
expect(clientError.request.url).to.equal(undefined);
210-
} else {
211-
expect(clientError.request.method).to.equal("GET");
212-
expect(clientError.request.url).to.equal(server.urlFor("/mocked-endpoint"));
213-
expect(_.find(clientError.request.headers,
214-
(_v, key) => key.toLowerCase() === 'host')
215-
).to.equal(`localhost:${server.port}`);
216-
}
204+
// Buffer overflows completely here, so parsing sees overwritten data as the start:
205+
expect(clientError.request.method?.slice(0, 10)).to.equal('XXXXXXXXXX');
206+
expect(clientError.request.url).to.equal(undefined);
217207

218208
const response = clientError.response as CompletedResponse;
219209
expect(response.statusCode).to.equal(431);
@@ -379,18 +369,9 @@ describe("Client error subscription", () => {
379369

380370
expect(clientError.errorCode).to.equal("HPE_HEADER_OVERFLOW");
381371

382-
if (semver.satisfies(process.version, '>=13')) {
383-
// Buffer overflows completely here, so parsing sees overwritten data as the start:
384-
expect(clientError.request.method?.slice(0, 10)).to.equal('XXXXXXXXXX');
385-
expect(clientError.request.url).to.equal(undefined);
386-
} else {
387-
expect(clientError.request.method).to.equal("GET");
388-
expect(clientError.request.url).to.equal("https://example.com/endpoint");
389-
expect(_.find(clientError.request.headers,
390-
(_v, key) => key.toLowerCase() === 'host')
391-
).to.equal('example.com');
392-
expect(clientError.request.headers['long-value']?.slice(0, 10)).to.equal('XXXXXXXXXX');
393-
}
372+
// Buffer overflows completely here, so parsing sees overwritten data as the start:
373+
expect(clientError.request.method?.slice(0, 10)).to.equal('XXXXXXXXXX');
374+
expect(clientError.request.url).to.equal(undefined);
394375

395376
const reportResponse = clientError.response as CompletedResponse;
396377
expect(reportResponse.statusCode).to.equal(431);

test/integration/subscriptions/tls-error-events.spec.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,10 @@ describe("TLS error subscriptions", () => {
141141
expect(tlsError.timingEvents.startTime).to.be.greaterThan(0);
142142
expect(tlsError.timingEvents.connectTimestamp).to.be.greaterThan(0);
143143

144-
if (semver.satisfies(process.version, '>=12')) {
145-
expect(tlsError.timingEvents.tunnelTimestamp)
146-
.to.be.greaterThan(tlsError.timingEvents.connectTimestamp);
147-
expect(tlsError.timingEvents.failureTimestamp)
148-
.to.be.greaterThan(tlsError.timingEvents.tunnelTimestamp!);
149-
} else {
150-
expect(tlsError.timingEvents.failureTimestamp)
151-
.to.be.greaterThan(tlsError.timingEvents.connectTimestamp);
152-
}
144+
expect(tlsError.timingEvents.tunnelTimestamp)
145+
.to.be.greaterThan(tlsError.timingEvents.connectTimestamp);
146+
expect(tlsError.timingEvents.failureTimestamp)
147+
.to.be.greaterThan(tlsError.timingEvents.tunnelTimestamp!);
153148

154149
await expectNoClientErrors();
155150
});

test/integration/verification.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import * as semver from 'semver';
2-
import { AbortController } from 'node-abort-controller';
3-
41
import { getLocal } from "../..";
52
import {
63
expect,
74
fetch,
85
URLSearchParams,
96
Headers,
10-
delay,
11-
HTTP_ABORTSIGNAL_SUPPORTED
7+
delay
128
} from "../test-utils";
139

1410
describe("HTTP request spying", function () {
@@ -82,8 +78,6 @@ describe("HTTP request spying", function () {
8278
});
8379

8480
it("should let you spy on incoming requests once the response is aborted", async function () {
85-
if (!semver.satisfies(process.version, HTTP_ABORTSIGNAL_SUPPORTED)) this.skip();
86-
8781
const endpointMock = await server.forGet("/mocked-endpoint").thenTimeout();
8882

8983
const abortController = new AbortController();

test/test-utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ export function makeAbortableRequest(server: Mockttp, path: string) {
243243
let abortController = new AbortController();
244244
fetch(server.urlFor(path), {
245245
method: 'POST',
246-
signal: abortController.signal as AbortSignal
246+
signal: abortController.signal
247247
}).catch(() => {});
248248
return abortController;
249249
}
@@ -298,18 +298,18 @@ export async function startDnsServer(callback: (question: dns2.DnsQuestion) => s
298298
});
299299
}
300300

301-
export const H2_TLS_ON_TLS_SUPPORTED = ">=12.17";
302-
export const HTTP_ABORTSIGNAL_SUPPORTED = ">=14.17";
301+
export const nodeSatisfies = (range: string) =>
302+
isNode && semver.satisfies(process.version, range);
303+
303304
export const DETAILED_TLS_ERROR_CODES = ">=18";
304305
export const NATIVE_FETCH_SUPPORTED = ">=18";
305306
export const SOCKET_RESET_SUPPORTED = "^16.17 || >=18.3";
306307
export const BROKEN_H1_OVER_H2_TUNNELLING = "^18.8";
307308
export const DEFAULT_KEEP_ALIVE = ">=19";
308309
export const FIXED_KEEP_ALIVE_BEHAVIOUR = ">=20";
309310
export const BROKEN_H2_OVER_H2_TUNNELLING = "~20.12"; // https://github.com/nodejs/node/issues/52344
310-
export const BROKEN_WASM_BUFFER_ISSUE = "~22.2"; // https://github.com/nodejs/node/issues/53075
311311

312-
export const defaultNodeConnectionHeader = semver.satisfies(process.version, DEFAULT_KEEP_ALIVE)
312+
export const defaultNodeConnectionHeader = nodeSatisfies(DEFAULT_KEEP_ALIVE)
313313
? 'keep-alive'
314314
: 'close';
315315

0 commit comments

Comments
 (0)