File tree 2 files changed +35
-0
lines changed 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -613,6 +613,24 @@ describe('node-fetch', () => {
613
613
} ) ;
614
614
} ) ;
615
615
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
+
616
634
it ( 'should handle DNS-error response' , ( ) => {
617
635
const url = 'http://domain.invalid' ;
618
636
return expect ( fetch ( url ) ) . to . eventually . be . rejected
Original file line number Diff line number Diff line change @@ -323,6 +323,23 @@ export default class TestServer {
323
323
} , 100 ) ;
324
324
}
325
325
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
+
326
343
if ( p === '/error/json' ) {
327
344
res . statusCode = 200 ;
328
345
res . setHeader ( 'Content-Type' , 'application/json' ) ;
You can’t perform that action at this time.
0 commit comments