Skip to content

Commit

Permalink
Test error on unreadable stream as body
Browse files Browse the repository at this point in the history
Fixes #1507
  • Loading branch information
szmarczak committed Apr 13, 2021
1 parent 7e1de42 commit e390b37
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/stream.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {promisify} from 'util';
import * as fs from 'fs';
import {PassThrough as PassThroughStream} from 'stream';
import {PassThrough as PassThroughStream, Readable as ReadableStream} from 'stream';
import * as stream from 'stream';
import test from 'ava';
import {Handler} from 'express';
Expand Down Expand Up @@ -436,6 +436,22 @@ test('destroys only once', async t => {
t.false(errored);
});

test('does not accept unreadable stream as body', withServer, async (t, server, got) => {
server.post('/', (_request, _response) => {});

const body = new ReadableStream();
body.push(null);
body.resume();

await pEvent(body, 'end');

const request = got.post({body});

await t.throwsAsync(request);

// TODO: Add assert message above.
});

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 e390b37

Please sign in to comment.