@@ -9,7 +9,6 @@ import { setAsyncLocalStorageAsyncContextStrategy } from '../src/async';
99import type { CloudflareOptions } from '../src/client' ;
1010import { CloudflareClient } from '../src/client' ;
1111import { wrapRequestHandler } from '../src/request' ;
12- import { resetSdk } from './testUtils' ;
1312
1413const MOCK_OPTIONS : CloudflareOptions = {
1514 dsn : 'https://public@dsn.ingest.sentry.io/1337' ,
@@ -26,7 +25,6 @@ describe('withSentry', () => {
2625
2726 beforeEach ( ( ) => {
2827 vi . clearAllMocks ( ) ;
29- resetSdk ( ) ;
3028 } ) ;
3129
3230 test ( 'passes through the response from the handler' , async ( ) => {
@@ -159,10 +157,6 @@ describe('withSentry', () => {
159157 {
160158 options : {
161159 ...MOCK_OPTIONS ,
162- // Set tracesSampleRate to enable the full path that adds request info
163- // (when tracesSampleRate is undefined/0, the fast path is used which
164- // only adds request info on errors for performance)
165- tracesSampleRate : 1 ,
166160 beforeSend ( event ) {
167161 sentryEvent = event ;
168162 return null ;
@@ -375,105 +369,6 @@ describe('withSentry', () => {
375369 } ) ;
376370 } ) ;
377371 } ) ;
378-
379- describe ( 'client disposal' , ( ) => {
380- test ( 'disposes of the client after the request completes to allow garbage collection' , async ( ) => {
381- // Create context with a waitUntil that captures promises
382- const waitUntilPromises : Promise < unknown > [ ] = [ ] ;
383- const context = {
384- waitUntil : vi . fn ( ( promise : Promise < unknown > ) => {
385- waitUntilPromises . push ( promise ) ;
386- } ) ,
387- passThroughOnException : vi . fn ( ) ,
388- } as unknown as ExecutionContext ;
389-
390- let capturedClient : CloudflareClient | undefined ;
391- await wrapRequestHandler (
392- {
393- options : {
394- ...MOCK_OPTIONS ,
395- tracesSampleRate : 1 , // Enable tracing to test full path
396- } ,
397- request : new Request ( 'https://example.com' ) ,
398- context,
399- } ,
400- ( ) => {
401- // Capture the client inside the handler
402- capturedClient = SentryCore . getClient ( ) as CloudflareClient ;
403- // Add Content-Length to skip streaming detection probing
404- const response = new Response ( 'test' ) ;
405- response . headers . set ( 'content-length' , '4' ) ;
406- return response ;
407- } ,
408- ) ;
409-
410- // Verify the client was created and has hooks before disposal
411- expect ( capturedClient ) . toBeInstanceOf ( CloudflareClient ) ;
412- const hooksBeforeDisposal = ( capturedClient as unknown as { _hooks : Record < string , Set < unknown > > } ) . _hooks ;
413- expect ( Object . keys ( hooksBeforeDisposal ) . length ) . toBeGreaterThan ( 0 ) ;
414-
415- // Wait for all waitUntil promises (flush + dispose happens here)
416- // The flushAndDispose promise is passed to waitUntil
417- expect ( waitUntilPromises . length ) . toBeGreaterThan ( 0 ) ;
418- await Promise . all ( waitUntilPromises ) ;
419-
420- // After disposal, the internal state should be cleared
421- // We can verify this by checking that the hooks are cleared
422- const hooks = ( capturedClient as unknown as { _hooks : Record < string , Set < unknown > > } ) . _hooks ;
423- const eventProcessors = ( capturedClient as unknown as { _eventProcessors : unknown [ ] } ) . _eventProcessors ;
424- const integrations = ( capturedClient as unknown as { _integrations : Record < string , unknown > } ) . _integrations ;
425-
426- expect ( Object . keys ( hooks ) ) . toHaveLength ( 0 ) ;
427- expect ( eventProcessors ) . toHaveLength ( 0 ) ;
428- expect ( Object . keys ( integrations ) ) . toHaveLength ( 0 ) ;
429- } ) ;
430-
431- test ( 'dispose clears span lifecycle listeners' , async ( ) => {
432- const client = new CloudflareClient ( {
433- dsn : MOCK_OPTIONS . dsn ,
434- transport : ( ) => ( { send : async ( ) => ( { } ) , flush : async ( ) => true } ) ,
435- integrations : [ ] ,
436- stackParser : ( ) => [ ] ,
437- } ) ;
438-
439- // Get the internal hooks before dispose
440- const hooksBeforeDispose = ( client as unknown as { _hooks : Record < string , Set < unknown > > } ) . _hooks ;
441- const spanStartHooks = hooksBeforeDispose [ 'spanStart' ] ;
442- const spanEndHooks = hooksBeforeDispose [ 'spanEnd' ] ;
443-
444- // Verify hooks exist before dispose
445- expect ( spanStartHooks ?. size ) . toBeGreaterThan ( 0 ) ;
446- expect ( spanEndHooks ?. size ) . toBeGreaterThan ( 0 ) ;
447-
448- // Dispose the client
449- client . dispose ( ) ;
450-
451- // Verify hooks are cleared after dispose
452- const hooksAfterDispose = ( client as unknown as { _hooks : Record < string , Set < unknown > > } ) . _hooks ;
453- expect ( Object . keys ( hooksAfterDispose ) ) . toHaveLength ( 0 ) ;
454- } ) ;
455-
456- test ( 'dispose clears pending spans' , async ( ) => {
457- const client = new CloudflareClient ( {
458- dsn : MOCK_OPTIONS . dsn ,
459- transport : ( ) => ( { send : async ( ) => ( { } ) , flush : async ( ) => true } ) ,
460- integrations : [ ] ,
461- stackParser : ( ) => [ ] ,
462- } ) ;
463-
464- // Add some pending spans
465- const pendingSpans = ( client as unknown as { _pendingSpans : Set < string > } ) . _pendingSpans ;
466- pendingSpans . add ( 'span1' ) ;
467- pendingSpans . add ( 'span2' ) ;
468- expect ( pendingSpans . size ) . toBe ( 2 ) ;
469-
470- // Dispose the client
471- client . dispose ( ) ;
472-
473- // Verify pending spans are cleared
474- expect ( pendingSpans . size ) . toBe ( 0 ) ;
475- } ) ;
476- } ) ;
477372} ) ;
478373
479374function createMockExecutionContext ( ) : ExecutionContext {
0 commit comments