@@ -2772,7 +2772,7 @@ describe('Client', () => {
27722772 expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
27732773 } ) ;
27742774
2775- it ( 'resets idle timeout when new logs are captured' , ( ) => {
2775+ it ( 'does not reset idle timeout when new logs are captured' , ( ) => {
27762776 const options = getDefaultTestClientOptions ( {
27772777 dsn : PUBLIC_DSN ,
27782778 enableLogs : true ,
@@ -2783,26 +2783,52 @@ describe('Client', () => {
27832783
27842784 const sendEnvelopeSpy = vi . spyOn ( client , 'sendEnvelope' ) ;
27852785
2786- // Add initial log
2786+ // Add initial log (starts the timer)
27872787 _INTERNAL_captureLog ( { message : 'test log 1' , level : 'info' } , scope ) ;
27882788
27892789 // Fast forward part of the idle timeout
27902790 vi . advanceTimersByTime ( 2500 ) ;
27912791
2792- // Add another log which should reset the timeout
2792+ // Add another log which should NOT reset the timeout
27932793 _INTERNAL_captureLog ( { message : 'test log 2' , level : 'info' } , scope ) ;
27942794
2795- // Fast forward the remaining time
2795+ // Fast forward the remaining time to reach the full timeout from the first log
27962796 vi . advanceTimersByTime ( 2500 ) ;
27972797
2798- // Should not have flushed yet since timeout was reset
2799- expect ( sendEnvelopeSpy ) . not . toHaveBeenCalled ( ) ;
2798+ // Should have flushed both logs since timeout was not reset
2799+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2800+ } ) ;
2801+
2802+ it ( 'starts new timer after timeout completes and flushes' , ( ) => {
2803+ const options = getDefaultTestClientOptions ( {
2804+ dsn : PUBLIC_DSN ,
2805+ enableLogs : true ,
2806+ } ) ;
2807+ const client = new TestClient ( options ) ;
2808+ const scope = new Scope ( ) ;
2809+ scope . setClient ( client ) ;
28002810
2801- // Fast forward the full timeout
2811+ const sendEnvelopeSpy = vi . spyOn ( client , 'sendEnvelope' ) ;
2812+
2813+ // First batch: Add a log and let it flush
2814+ _INTERNAL_captureLog ( { message : 'test log 1' , level : 'info' } , scope ) ;
2815+
2816+ // Fast forward to trigger the first flush
28022817 vi . advanceTimersByTime ( 5000 ) ;
28032818
2804- // Now should have flushed both logs
28052819 expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2820+
2821+ // Second batch: Add another log after the first flush completed
2822+ _INTERNAL_captureLog ( { message : 'test log 2' , level : 'info' } , scope ) ;
2823+
2824+ // Should not have flushed yet
2825+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
2826+
2827+ // Fast forward to trigger the second flush
2828+ vi . advanceTimersByTime ( 5000 ) ;
2829+
2830+ // Should have flushed the second log
2831+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 2 ) ;
28062832 } ) ;
28072833
28082834 it ( 'flushes logs on flush event' , ( ) => {
0 commit comments