Skip to content

Commit

Permalink
feat: support reading from the request stream (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored and JustinBeckwith committed Aug 7, 2019
1 parent 12901a0 commit ae23054
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,12 @@ function teenyRequest(
options.compress = false;
fetch(uri, options).then(
res => {
res.body.on('error', err => {
console.log('whoa there was an error, passing it on: ' + err);
requestStream.emit('error', err);
});
res.body
.on('error', err => {
console.log('whoa there was an error, passing it on: ' + err);
requestStream.emit('error', err);
})
.pipe(requestStream);

const response = fetchToRequestResponse(options, res);
requestStream.emit('response', response);
Expand Down
11 changes: 11 additions & 0 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,15 @@ describe('teeny', () => {
return done();
});
});

it('should provide a readable stream', done => {
const scope = mockJson();
teenyRequest({uri})
.on('error', done)
.on('data', data => {
const json = JSON.parse(data.toString());
assert.deepStrictEqual(json, {hello: '🌍'});
done();
});
});
});

0 comments on commit ae23054

Please sign in to comment.