Skip to content

Commit 50ef99a

Browse files
committed
Fixes to be compatible with Node.js 14.1.0
1 parent e23b7f9 commit 50ef99a

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"@types/benchmark": "^1.0.31",
6363
"@types/express": "^4.17.6",
6464
"@types/lolex": "^5.1.0",
65-
"@types/node": "13.1.2",
65+
"@types/node": "^13.13.4",
6666
"@types/node-fetch": "^2.5.5",
6767
"@types/request": "^2.48.4",
6868
"@types/sinon": "^9.0.0",

source/core/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
964964
});
965965

966966
response.once('error', (error: Error) => {
967+
// Force clean-up, because some packages don't do this.
968+
// TODO: Fix decompress-response
969+
response.destroy();
970+
967971
this._beforeError(new ReadError(error, this));
968972
});
969973

@@ -1140,6 +1144,9 @@ export default class Request extends Duplex implements RequestEvents<Request> {
11401144
});
11411145

11421146
request.once('error', (error: Error) => {
1147+
// Force clean-up, because some packages (e.g. nock) don't do this.
1148+
request.destroy();
1149+
11431150
if (error instanceof TimedOutTimeoutError) {
11441151
error = new TimeoutError(error, this.timings!, this);
11451152
} else {

test/agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ test('socket connect listener cleaned up after request', withServer, async (t, s
173173
afterResponse: [
174174
async (response, retryWithMergedOptions) => {
175175
// Force clean-up
176-
response.socket.destroy();
176+
response.socket?.destroy();
177177

178178
// Unauthorized
179179
if (response.statusCode === 401) {

test/retry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import EventEmitter = require('events');
1+
import {EventEmitter} from 'events';
22
import {PassThrough as PassThroughStream} from 'stream';
33
import {Socket} from 'net';
44
import http = require('http');
@@ -135,6 +135,7 @@ test('custom error codes', async t => {
135135
const emitter = new EventEmitter() as http.ClientRequest;
136136
emitter.abort = () => {};
137137
emitter.end = () => {};
138+
emitter.destroy = () => {};
138139

139140
const error = new Error('Snap!');
140141
(error as Error & {code: typeof errorCode}).code = errorCode;

test/timeout.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {promisify} from 'util';
2-
import EventEmitter = require('events');
2+
import {EventEmitter} from 'events';
33
import {PassThrough as PassThroughStream} from 'stream';
44
import stream = require('stream');
55
import http = require('http');

0 commit comments

Comments
 (0)