From 7b1567cc787e4f97cd1dce242d22dcac1dde860f Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Wed, 26 Feb 2020 22:18:33 -0800 Subject: [PATCH] build: fix node 13 test error (#137) --- package.json | 2 +- test/agents.ts | 3 +-- test/index.ts | 20 +++++++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 7c4b4b5..662c518 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "mocha": "^7.0.0", "nock": "^12.0.0", "sinon": "^9.0.0", - "typescript": "3.6.4" + "typescript": "~3.8.2" }, "nyc": { "exclude": [ diff --git a/test/agents.ts b/test/agents.ts index b2ec435..9524d16 100644 --- a/test/agents.ts +++ b/test/agents.ts @@ -15,9 +15,8 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, afterEach} from 'mocha'; import * as http from 'http'; -import * as https from 'https'; import * as sinon from 'sinon'; import {getAgent} from '../src/agents'; diff --git a/test/index.ts b/test/index.ts index f1cbecf..0e25b74 100644 --- a/test/index.ts +++ b/test/index.ts @@ -15,14 +15,12 @@ */ import * as assert from 'assert'; -import {describe, it} from 'mocha'; +import {describe, it, afterEach} from 'mocha'; import * as nock from 'nock'; -import {Readable} from 'stream'; +import {Readable, PassThrough} from 'stream'; import * as sinon from 'sinon'; import {teenyRequest} from '../src'; -import {PassThrough} from 'stream'; - // tslint:disable-next-line variable-name const HttpProxyAgent = require('http-proxy-agent'); // tslint:disable-next-line variable-name @@ -249,10 +247,18 @@ describe('teeny', () => { const scope = mockJson(); const stream = teenyRequest({uri}).on('error', done); stream.on('response', responseStream => { - assert.strictEqual(responseStream.body._readableState.pipesCount, 0); - + // We are using an internal property of Readable to get the number of + // active readers. The property changed from `pipesCount: number` in + // Node.js 12.x and below to `pipes: Array` in Node.js 13.x. + let numPipes = + responseStream.body._readableState.pipesCount ?? + responseStream.body._readableState.pipes?.length; + assert.strictEqual(numPipes, 0); stream.on('data', () => { - assert.strictEqual(responseStream.body._readableState.pipesCount, 1); + numPipes = + responseStream.body._readableState.pipesCount ?? + responseStream.body._readableState.pipes?.length; + assert.strictEqual(numPipes, 1); done(); }); });