Skip to content

Commit

Permalink
build: fix node 13 test error (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith committed Feb 27, 2020
1 parent d82042f commit 7b1567c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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": [
Expand Down
3 changes: 1 addition & 2 deletions test/agents.ts
Expand Up @@ -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';

Expand Down
20 changes: 13 additions & 7 deletions test/index.ts
Expand Up @@ -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
Expand Down Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 7b1567c

Please sign in to comment.