Skip to content

Commit f28d2b3

Browse files
Gozalatekwiz
authored andcommitted
chore: create test case for the problem
1 parent 4abbfd2 commit f28d2b3

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

test/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,24 @@ describe('node-fetch', () => {
613613
});
614614
});
615615

616+
it('should handle network-error in chunked response', () => {
617+
const url = `${base}error/premature/chunked`;
618+
return fetch(url).then(res => {
619+
expect(res.status).to.equal(200);
620+
expect(res.ok).to.be.true;
621+
622+
const read = async (body) => {
623+
const chunks = [];
624+
for await (const chunk of body) {
625+
chunks.push(chunk);
626+
}
627+
return chunks;
628+
};
629+
630+
return expect(read(res.body)).to.eventually.be.rejectedWith(Error);
631+
});
632+
});
633+
616634
it('should handle DNS-error response', () => {
617635
const url = 'http://domain.invalid';
618636
return expect(fetch(url)).to.eventually.be.rejected

test/utils/server.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,23 @@ export default class TestServer {
323323
}, 100);
324324
}
325325

326+
if (p === '/error/premature/chunked') {
327+
res.writeHead(200, {
328+
'content-type': 'application/json',
329+
'transfer-encoding': 'chunked'
330+
});
331+
332+
res.write(`${JSON.stringify({ data: 'hi' })}\n`);
333+
334+
setTimeout(() => {
335+
res.write(`${JSON.stringify({ data: 'bye' })}\n`);
336+
}, 100);
337+
338+
setTimeout(() => {
339+
res.destroy()
340+
}, 200);
341+
}
342+
326343
if (p === '/error/json') {
327344
res.statusCode = 200;
328345
res.setHeader('Content-Type', 'application/json');

0 commit comments

Comments
 (0)