Skip to content

Commit

Permalink
Add a test for #1438 (#1469)
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Sep 20, 2020
1 parent 5d62958 commit c31366b
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion test/promise.ts
@@ -1,6 +1,7 @@
import {ReadStream} from 'fs';
import {ClientRequest, IncomingMessage} from 'http';
import test from 'ava';
import {Response} from '../source';
import {Response, CancelError} from '../source';
import withServer from './helpers/with-server';

test('emits request event as promise', withServer, async (t, server, got) => {
Expand Down Expand Up @@ -50,3 +51,31 @@ test('no unhandled `The server aborted pending request` rejection', withServer,

await t.throwsAsync(got(''));
});

test('promise.json() can be called before a file stream body is open', withServer, async (t, server, got) => {
server.post('/', (request, response) => {
request.resume();
request.once('end', () => {
response.end('""');
});
});

// @ts-expect-error @types/node has wrong types.
const body = new ReadStream('', {
fs: {
open: () => {},
read: () => {},
close: () => {}
}
});

const promise = got({body});
const checks = [
t.throwsAsync(promise, {instanceOf: CancelError}),
t.throwsAsync(promise.json(), {instanceOf: CancelError})
];

promise.cancel();

await Promise.all(checks);
});

0 comments on commit c31366b

Please sign in to comment.