File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
typescript-sdk/packages/client/src/transform/__tests__ Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,40 @@ describe("transformHttpEventStream", () => {
5454 expect ( receivedEvents ) . toEqual ( [ mockBaseEvent ] ) ;
5555 } ) ;
5656
57+ test ( "should emit RUN_ERROR and complete on AbortError without erroring" , ( ) => {
58+ const mockHttpSource = new Subject < HttpEvent > ( ) ;
59+ const receivedEvents : BaseEvent [ ] = [ ] ;
60+ let completed = false ;
61+ let receivedError : unknown = undefined ;
62+
63+ const result$ = transformHttpEventStream ( mockHttpSource ) ;
64+ result$ . subscribe ( {
65+ next : ( event ) => receivedEvents . push ( event ) ,
66+ error : ( err ) => {
67+ receivedError = err ;
68+ } ,
69+ complete : ( ) => {
70+ completed = true ;
71+ } ,
72+ } ) ;
73+
74+ mockHttpSource . next ( {
75+ type : HttpEventType . HEADERS ,
76+ status : 200 ,
77+ headers : new Headers ( [ [ "content-type" , "text/event-stream" ] ] ) ,
78+ } ) ;
79+
80+ const abortError = { name : "AbortError" } as DOMException ;
81+ mockHttpSource . error ( abortError ) ;
82+
83+ expect ( receivedEvents ) . toHaveLength ( 1 ) ;
84+ expect ( receivedEvents [ 0 ] . type ) . toBe ( EventType . RUN_ERROR ) ;
85+ const runErrorEvent = receivedEvents [ 0 ] as any ;
86+ expect ( runErrorEvent . rawEvent ) . toBe ( abortError ) ;
87+ expect ( completed ) . toBe ( true ) ;
88+ expect ( receivedError ) . toBeUndefined ( ) ;
89+ } ) ;
90+
5791 test ( "should handle parseProtoStream errors" , ( done ) => {
5892 // Given
5993 const mockHttpSource = new Subject < HttpEvent > ( ) ;
You can’t perform that action at this time.
0 commit comments