Skip to content

Commit

Permalink
Test body streams from readable-stream
Browse files Browse the repository at this point in the history
Fixes #1503
  • Loading branch information
szmarczak committed Apr 13, 2021
1 parent e390b37 commit 3f45e47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -66,6 +66,7 @@
"@types/node-fetch": "^2.5.8",
"@types/pem": "^1.9.5",
"@types/pify": "^5.0.0",
"@types/readable-stream": "^2.3.9",
"@types/request": "^2.48.5",
"@types/sinon": "^9.0.9",
"@types/tough-cookie": "^4.0.0",
Expand All @@ -86,6 +87,7 @@
"p-event": "^4.2.0",
"pem": "^1.14.4",
"pify": "^5.0.0",
"readable-stream": "^3.6.0",
"request": "^2.88.2",
"sinon": "^9.2.4",
"slow-stream": "0.0.4",
Expand Down
18 changes: 18 additions & 0 deletions test/stream.ts
@@ -1,6 +1,7 @@
import {promisify} from 'util';
import * as fs from 'fs';
import {PassThrough as PassThroughStream, Readable as ReadableStream} from 'stream';
import {Readable as Readable2} from 'readable-stream';
import * as stream from 'stream';
import test from 'ava';
import {Handler} from 'express';
Expand Down Expand Up @@ -452,6 +453,23 @@ test('does not accept unreadable stream as body', withServer, async (t, server,
// TODO: Add assert message above.
});

test('accepts readable-stream as body', withServer, async (t, server, got) => {
server.post('/', (request, response) => {
request.pipe(response);
});

const body = new Readable2({
read() {
this.push('ok');
this.push(null);
}
});

const response = await got.post({body});

t.is(response.body, 'ok');
});

if (Number.parseInt(process.versions.node.split('.')[0]!, 10) <= 12) {
test('does not emit end event on error', withServer, async (t, server, got) => {
server.get('/', infiniteHandler);
Expand Down

0 comments on commit 3f45e47

Please sign in to comment.