@@ -92,26 +92,24 @@ const simulateDisconnection = async (
9292 eventEmitter : EventEmitter ,
9393 connectionId : string ,
9494) => {
95- eventEmitter . emitSync ( 'onWebSocketEvent' , {
95+ await eventEmitter . emitSync ( 'onWebSocketEvent' , {
9696 event : {
9797 type : 'close' ,
9898 id : connectionId ,
9999 } ,
100100 } ) ;
101- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
102101} ;
103102
104103const simulateReconnection = async (
105104 eventEmitter : EventEmitter ,
106105 connectionId : string ,
107106) => {
108- eventEmitter . emitSync ( 'onWebSocketEvent' , {
107+ await eventEmitter . emitSync ( 'onWebSocketEvent' , {
109108 event : {
110109 type : 'open' ,
111110 id : connectionId ,
112111 } ,
113112 } ) ;
114- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
115113} ;
116114
117115const triggerConnectionRecoveryCallbacks = async (
@@ -274,8 +272,7 @@ describe('SubscriberAdapter', () => {
274272 . mockResolvedValue ( undefined ) ;
275273 const notification = createMockNotification ( ) ;
276274
277- mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
278- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
275+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
279276
280277 expect ( mockLogger . warn ) . toHaveBeenCalledWith (
281278 loggerScope ,
@@ -302,10 +299,9 @@ describe('SubscriberAdapter', () => {
302299 98765 ,
303300 ) ;
304301
305- mockEventEmitter . emitSync ( 'onWebSocketEvent' , {
302+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , {
306303 event : confirmationMessage ,
307304 } ) ;
308- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
309305
310306 const confirmedSubscription : ConfirmedSubscription = {
311307 ...request ,
@@ -328,8 +324,7 @@ describe('SubscriberAdapter', () => {
328324 value : { lamports : 116044436802 } ,
329325 } ) ;
330326
331- mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
332- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
327+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
333328
334329 expect ( callbacks . onNotification ) . toHaveBeenCalledWith ( {
335330 context : { Slot : 348893275 } ,
@@ -348,8 +343,7 @@ describe('SubscriberAdapter', () => {
348343 value : { lamports : 116044436802 } ,
349344 } ) ;
350345
351- mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
352- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
346+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
353347
354348 expect ( mockLogger . error ) . toHaveBeenCalledWith (
355349 loggerScope ,
@@ -365,8 +359,7 @@ describe('SubscriberAdapter', () => {
365359 it ( 'logs a warning and does nothing' , async ( ) => {
366360 const message = createMockConfirmationMessage ( 'some-subscription-id' ) ;
367361
368- mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
369- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
362+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
370363
371364 expect ( mockLogger . warn ) . toHaveBeenCalledWith (
372365 loggerScope ,
@@ -405,8 +398,10 @@ describe('SubscriberAdapter', () => {
405398 it ( 'confirms the subscription' , async ( ) => {
406399 const confirmationMessage = createMockConfirmationMessage ( ) ;
407400
408- mockEventEmitter . emitSync ( 'onWebSocketEvent' , confirmationMessage ) ;
409- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
401+ await mockEventEmitter . emitSync (
402+ 'onWebSocketEvent' ,
403+ confirmationMessage ,
404+ ) ;
410405
411406 // Verify the confirmation was updated to 'confirmed'
412407 const confirmedSubscription : ConfirmedSubscription = {
@@ -435,8 +430,7 @@ describe('SubscriberAdapter', () => {
435430 } ,
436431 ) ;
437432
438- mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
439- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
433+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , notification ) ;
440434
441435 expect ( callbacks . onNotification ) . toHaveBeenCalledWith ( {
442436 context : { Slot : 348893275 } ,
@@ -480,8 +474,7 @@ describe('SubscriberAdapter', () => {
480474 } ) ;
481475
482476 it ( 'logs the error' , async ( ) => {
483- mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
484- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
477+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
485478
486479 expect ( mockLogger . error ) . toHaveBeenCalledWith (
487480 loggerScope ,
@@ -494,8 +487,7 @@ describe('SubscriberAdapter', () => {
494487 } ) ;
495488
496489 it ( 'calls the subscription callback with the error' , async ( ) => {
497- mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
498- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
490+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
499491
500492 expect ( callbacks . onSubscriptionFailed ) . toHaveBeenCalledWith ( {
501493 code : - 32000 ,
@@ -506,8 +498,7 @@ describe('SubscriberAdapter', () => {
506498
507499 describe ( 'when there is no subscription for the message' , ( ) => {
508500 it ( 'logs an error and does nothing' , async ( ) => {
509- mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
510- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
501+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
511502
512503 expect ( mockLogger . error ) . toHaveBeenCalledWith (
513504 loggerScope ,
@@ -539,8 +530,7 @@ describe('SubscriberAdapter', () => {
539530 } ;
540531
541532 it ( 'logs an error and does nothing' , async ( ) => {
542- mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
543- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
533+ await mockEventEmitter . emitSync ( 'onWebSocketEvent' , message ) ;
544534
545535 expect ( mockLogger . error ) . toHaveBeenCalledWith (
546536 loggerScope ,
@@ -769,8 +759,10 @@ describe('SubscriberAdapter', () => {
769759 subscriptionId ,
770760 98765 ,
771761 ) ;
772- mockEventEmitter . emitSync ( 'onWebSocketEvent' , confirmationMessage ) ;
773- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ; // Emitting the event is async. We need to wait for it to complete.
762+ await mockEventEmitter . emitSync (
763+ 'onWebSocketEvent' ,
764+ confirmationMessage ,
765+ ) ;
774766
775767 jest . spyOn ( mockSubscriptionRepository , 'findBy' ) . mockResolvedValue ( {
776768 ...pendingSubscription ,
0 commit comments