@@ -18,7 +18,6 @@ vi.mock('@sentry/core', async requireActual => {
1818
1919describe ( 'BrowserClient' , ( ) => {
2020 let client : BrowserClient ;
21- const DEFAULT_FLUSH_INTERVAL = 5000 ;
2221
2322 afterEach ( ( ) => {
2423 vi . useRealTimers ( ) ;
@@ -78,57 +77,24 @@ describe('BrowserClient', () => {
7877 expect ( sentryCore . _INTERNAL_flushLogsBuffer ) . toHaveBeenCalledWith ( client ) ;
7978 } ) ;
8079
81- it ( 'flushes logs on flush event ' , ( ) => {
80+ it ( 'inherits log weight-based flushing from base Client ' , ( ) => {
8281 const scope = new Scope ( ) ;
8382 scope . setClient ( client ) ;
8483
85- // Add some logs
86- sentryCore . _INTERNAL_captureLog ( { level : 'info' , message : 'test log 1' } , scope ) ;
87- sentryCore . _INTERNAL_captureLog ( { level : 'info' , message : 'test log 2' } , scope ) ;
84+ // Spy on sendEnvelope to verify flushing happens
85+ const sendEnvelopeSpy = vi . spyOn ( client , 'sendEnvelope' ) ;
8886
89- // Trigger flush event
90- client . emit ( 'flush' ) ;
91-
92- expect ( sentryCore . _INTERNAL_flushLogsBuffer ) . toHaveBeenCalledWith ( client ) ;
93- } ) ;
94-
95- it ( 'flushes logs after idle timeout' , ( ) => {
96- const scope = new Scope ( ) ;
97- scope . setClient ( client ) ;
98-
99- // Add a log which will trigger afterCaptureLog event
87+ // Add a log and verify the base Client functionality works
10088 sentryCore . _INTERNAL_captureLog ( { level : 'info' , message : 'test log' } , scope ) ;
10189
102- // Fast forward the idle timeout
103- vi . advanceTimersByTime ( DEFAULT_FLUSH_INTERVAL ) ;
104-
105- expect ( sentryCore . _INTERNAL_flushLogsBuffer ) . toHaveBeenCalledWith ( client ) ;
106- } ) ;
107-
108- it ( 'resets idle timeout when new logs are captured' , ( ) => {
109- const scope = new Scope ( ) ;
110- scope . setClient ( client ) ;
111-
112- // Add initial log
113- sentryCore . _INTERNAL_captureLog ( { level : 'info' , message : 'test log 1' } , scope ) ;
114-
115- // Fast forward part of the idle timeout
116- vi . advanceTimersByTime ( DEFAULT_FLUSH_INTERVAL / 2 ) ;
90+ // Verify weight tracking is active
91+ expect ( ( client as any ) . _logWeight ) . toBeGreaterThan ( 0 ) ;
11792
118- // Add another log which should reset the timeout
119- sentryCore . _INTERNAL_captureLog ( { level : 'info' , message : 'test log 2' } , scope ) ;
120-
121- // Fast forward the remaining time
122- vi . advanceTimersByTime ( DEFAULT_FLUSH_INTERVAL / 2 ) ;
123-
124- // Should not have flushed yet since timeout was reset
125- expect ( sentryCore . _INTERNAL_flushLogsBuffer ) . not . toHaveBeenCalled ( ) ;
126-
127- // Fast forward the full timeout
128- vi . advanceTimersByTime ( DEFAULT_FLUSH_INTERVAL ) ;
93+ // Trigger flush and verify it works
94+ client . emit ( 'flush' ) ;
12995
130- // Now should have flushed both logs
131- expect ( sentryCore . _INTERNAL_flushLogsBuffer ) . toHaveBeenCalledWith ( client ) ;
96+ expect ( sendEnvelopeSpy ) . toHaveBeenCalledTimes ( 1 ) ;
97+ expect ( ( client as any ) . _logWeight ) . toBe ( 0 ) ;
13298 } ) ;
13399 } ) ;
134100} ) ;
0 commit comments