@@ -107,9 +107,8 @@ describe('Firebase Functions > Call', () => {
107107 long : 420
108108 } ) ;
109109 } catch ( err ) {
110- console . error ( err )
110+ console . error ( err ) ;
111111 }
112-
113112 } ) ;
114113
115114 it ( 'scalars' , async ( ) => {
@@ -325,7 +324,7 @@ describe('Firebase Functions > Stream', () => {
325324
326325 afterEach ( ( ) => {
327326 mockFetch . restore ( ) ;
328- } )
327+ } ) ;
329328
330329 it ( 'successfully streams data and resolves final result' , async ( ) => {
331330 const mockResponse = new ReadableStream ( {
@@ -356,6 +355,34 @@ describe('Firebase Functions > Stream', () => {
356355 expect ( await streamResult . data ) . to . equal ( 'Final Result' ) ;
357356 } ) ;
358357
358+ it ( 'successfully process request chunk with multiple events' , async ( ) => {
359+ const mockResponse = new ReadableStream ( {
360+ start ( controller ) {
361+ controller . enqueue ( new TextEncoder ( ) . encode ( 'data: {"message":"Hello"}\n\ndata: {"message":"World"}\n' ) ) ;
362+ controller . enqueue ( new TextEncoder ( ) . encode ( 'data: {"result":"Final Result"}\n' ) ) ;
363+ controller . close ( ) ;
364+ }
365+ } ) ;
366+
367+ mockFetch . resolves ( {
368+ body : mockResponse ,
369+ headers : new Headers ( { 'Content-Type' : 'text/event-stream' } ) ,
370+ status : 200 ,
371+ statusText : 'OK' ,
372+ } as Response ) ;
373+
374+ const func = httpsCallable < Record < string , any > , string , string > ( functions , 'streamTest' ) ;
375+ const streamResult = await func . stream ( { } ) ;
376+
377+ const messages : string [ ] = [ ] ;
378+ for await ( const message of streamResult . stream ) {
379+ messages . push ( message ) ;
380+ }
381+
382+ expect ( messages ) . to . deep . equal ( [ 'Hello' , 'World' ] ) ;
383+ expect ( await streamResult . data ) . to . equal ( 'Final Result' ) ;
384+ } ) ;
385+
359386 it ( 'handles network errors' , async ( ) => {
360387 mockFetch . rejects ( new Error ( 'Network error' ) ) ;
361388
@@ -372,7 +399,7 @@ describe('Firebase Functions > Stream', () => {
372399 expect ( ( error as FunctionsError ) . code ) . to . equal ( `${ FUNCTIONS_TYPE } /internal` ) ;
373400 }
374401 expect ( errorThrown ) . to . be . true ;
375- expectError ( streamResult . data , "internal" , "Internal" ) ;
402+ await expectError ( streamResult . data , "internal" , "Internal" ) ;
376403 } ) ;
377404
378405 it ( 'handles server-side errors' , async ( ) => {
@@ -405,7 +432,7 @@ describe('Firebase Functions > Stream', () => {
405432 }
406433
407434 expect ( errorThrown ) . to . be . true ;
408- expectError ( streamResult . data , "invalid-argument" , "Invalid input" )
435+ await expectError ( streamResult . data , "invalid-argument" , "Invalid input" ) ;
409436 } ) ;
410437
411438 it ( 'includes authentication and app check tokens in request headers' , async ( ) => {
@@ -497,7 +524,7 @@ describe('Firebase Functions > Stream', () => {
497524 expect ( ( error as FunctionsError ) . code ) . to . equal ( `${ FUNCTIONS_TYPE } /cancelled` ) ;
498525 }
499526 expect ( errorThrown ) . to . be . true ;
500- expectError ( streamResult . data , "cancelled" , "Request was cancelled" )
527+ await expectError ( streamResult . data , "cancelled" , "Request was cancelled" ) ;
501528 } ) ;
502529
503530 it ( 'aborts during streaming' , async ( ) => {
@@ -539,7 +566,7 @@ describe('Firebase Functions > Stream', () => {
539566 expect ( ( error as FunctionsError ) . code ) . to . equal ( `${ FUNCTIONS_TYPE } /cancelled` ) ;
540567 }
541568 expect ( messages ) . to . deep . equal ( [ 'First' ] ) ;
542- expectError ( streamResult . data , "cancelled" , "Request was cancelled" )
569+ await expectError ( streamResult . data , "cancelled" , "Request was cancelled" ) ;
543570 } ) ;
544571
545572 it ( 'fails immediately with pre-aborted signal' , async ( ) => {
@@ -564,7 +591,7 @@ describe('Firebase Functions > Stream', () => {
564591 expect ( ( error as FunctionsError ) . code ) . to . equal ( `${ FUNCTIONS_TYPE } /cancelled` ) ;
565592 }
566593 expect ( errorThrown ) . to . be . true ;
567- expectError ( streamResult . data , "cancelled" , "Request was cancelled" )
594+ await expectError ( streamResult . data , "cancelled" , "Request was cancelled" ) ;
568595 } ) ;
569596
570597 it ( 'properly handles AbortSignal.timeout()' , async ( ) => {
@@ -589,13 +616,13 @@ describe('Firebase Functions > Stream', () => {
589616 const streamResult = await func . stream ( { } , { signal } ) ;
590617
591618 try {
592- for await ( const message of streamResult . stream ) {
619+ for await ( const _ of streamResult . stream ) {
593620 // Should not execute
594621 }
595622 throw new Error ( 'Stream should have timed out' ) ;
596623 } catch ( error ) {
597624 expect ( ( error as FunctionsError ) . code ) . to . equal ( `${ FUNCTIONS_TYPE } /cancelled` ) ;
598625 }
599- expectError ( streamResult . data , "cancelled" , "Request was cancelled" )
626+ await expectError ( streamResult . data , "cancelled" , "Request was cancelled" ) ;
600627 } ) ;
601628} ) ;
0 commit comments