Skip to content

Commit

Permalink
Fixes to be compatible with Node.js 14.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed May 3, 2020
1 parent e23b7f9 commit 50ef99a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@types/benchmark": "^1.0.31",
"@types/express": "^4.17.6",
"@types/lolex": "^5.1.0",
"@types/node": "13.1.2",
"@types/node": "^13.13.4",
"@types/node-fetch": "^2.5.5",
"@types/request": "^2.48.4",
"@types/sinon": "^9.0.0",
Expand Down
7 changes: 7 additions & 0 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
});

response.once('error', (error: Error) => {
// Force clean-up, because some packages don't do this.
// TODO: Fix decompress-response
response.destroy();

this._beforeError(new ReadError(error, this));
});

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

request.once('error', (error: Error) => {
// Force clean-up, because some packages (e.g. nock) don't do this.
request.destroy();

if (error instanceof TimedOutTimeoutError) {
error = new TimeoutError(error, this.timings!, this);
} else {
Expand Down
2 changes: 1 addition & 1 deletion test/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test('socket connect listener cleaned up after request', withServer, async (t, s
afterResponse: [
async (response, retryWithMergedOptions) => {
// Force clean-up
response.socket.destroy();
response.socket?.destroy();

// Unauthorized
if (response.statusCode === 401) {
Expand Down
3 changes: 2 additions & 1 deletion test/retry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter = require('events');
import {EventEmitter} from 'events';
import {PassThrough as PassThroughStream} from 'stream';
import {Socket} from 'net';
import http = require('http');
Expand Down Expand Up @@ -135,6 +135,7 @@ test('custom error codes', async t => {
const emitter = new EventEmitter() as http.ClientRequest;
emitter.abort = () => {};
emitter.end = () => {};
emitter.destroy = () => {};

const error = new Error('Snap!');
(error as Error & {code: typeof errorCode}).code = errorCode;
Expand Down
2 changes: 1 addition & 1 deletion test/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {promisify} from 'util';
import EventEmitter = require('events');
import {EventEmitter} from 'events';
import {PassThrough as PassThroughStream} from 'stream';
import stream = require('stream');
import http = require('http');
Expand Down

0 comments on commit 50ef99a

Please sign in to comment.