@@ -174,4 +174,85 @@ describe('instrumentFetch', () => {
174174 await Promise . all ( waits ) ;
175175 expect ( flush ) . toHaveBeenCalledOnce ( ) ;
176176 } ) ;
177+
178+ test ( 'OPTIONS requests bypass SDK instrumentation' , async ( ) => {
179+ const originalFetch = vi . fn ( ) . mockReturnValue ( new Response ( 'options response' ) ) ;
180+ const handler = {
181+ fetch : originalFetch ,
182+ } satisfies ExportedHandler < typeof MOCK_ENV > ;
183+
184+ const optionsCallback = vi . fn ( ) . mockReturnValue ( { dsn : MOCK_ENV . SENTRY_DSN } ) ;
185+
186+ const wrappedHandler = withSentry ( optionsCallback , handler ) ;
187+ const result = await wrappedHandler . fetch ?.(
188+ new Request ( 'https://example.com' , { method : 'OPTIONS' } ) ,
189+ MOCK_ENV ,
190+ createMockExecutionContext ( ) ,
191+ ) ;
192+
193+ expect ( originalFetch ) . toHaveBeenCalledTimes ( 1 ) ;
194+ expect ( optionsCallback ) . not . toHaveBeenCalled ( ) ;
195+ expect ( result ?. status ) . toBe ( 200 ) ;
196+ if ( result ) {
197+ expect ( await result . text ( ) ) . toBe ( 'options response' ) ;
198+ }
199+ } ) ;
200+
201+ test ( 'HEAD requests bypass SDK instrumentation' , async ( ) => {
202+ const originalFetch = vi . fn ( ) . mockReturnValue ( new Response ( 'head response' ) ) ;
203+ const handler = {
204+ fetch : originalFetch ,
205+ } satisfies ExportedHandler < typeof MOCK_ENV > ;
206+
207+ const optionsCallback = vi . fn ( ) . mockReturnValue ( { dsn : MOCK_ENV . SENTRY_DSN } ) ;
208+
209+ const wrappedHandler = withSentry ( optionsCallback , handler ) ;
210+ const result = await wrappedHandler . fetch ?.(
211+ new Request ( 'https://example.com' , { method : 'HEAD' } ) ,
212+ MOCK_ENV ,
213+ createMockExecutionContext ( ) ,
214+ ) ;
215+
216+ expect ( originalFetch ) . toHaveBeenCalledTimes ( 1 ) ;
217+ expect ( optionsCallback ) . not . toHaveBeenCalled ( ) ;
218+ expect ( result ?. status ) . toBe ( 200 ) ;
219+ } ) ;
220+
221+ test ( 'GET requests are instrumented' , async ( ) => {
222+ const originalFetch = vi . fn ( ) . mockReturnValue ( new Response ( 'get response' ) ) ;
223+ const handler = {
224+ fetch : originalFetch ,
225+ } satisfies ExportedHandler < typeof MOCK_ENV > ;
226+
227+ const optionsCallback = vi . fn ( ) . mockReturnValue ( { dsn : MOCK_ENV . SENTRY_DSN } ) ;
228+
229+ const wrappedHandler = withSentry ( optionsCallback , handler ) ;
230+ await wrappedHandler . fetch ?.(
231+ new Request ( 'https://example.com' , { method : 'GET' } ) ,
232+ MOCK_ENV ,
233+ createMockExecutionContext ( ) ,
234+ ) ;
235+
236+ expect ( originalFetch ) . toHaveBeenCalledTimes ( 1 ) ;
237+ expect ( optionsCallback ) . toHaveBeenCalledTimes ( 1 ) ;
238+ } ) ;
239+
240+ test ( 'POST requests are instrumented' , async ( ) => {
241+ const originalFetch = vi . fn ( ) . mockReturnValue ( new Response ( 'post response' ) ) ;
242+ const handler = {
243+ fetch : originalFetch ,
244+ } satisfies ExportedHandler < typeof MOCK_ENV > ;
245+
246+ const optionsCallback = vi . fn ( ) . mockReturnValue ( { dsn : MOCK_ENV . SENTRY_DSN } ) ;
247+
248+ const wrappedHandler = withSentry ( optionsCallback , handler ) ;
249+ await wrappedHandler . fetch ?.(
250+ new Request ( 'https://example.com' , { method : 'POST' } ) ,
251+ MOCK_ENV ,
252+ createMockExecutionContext ( ) ,
253+ ) ;
254+
255+ expect ( originalFetch ) . toHaveBeenCalledTimes ( 1 ) ;
256+ expect ( optionsCallback ) . toHaveBeenCalledTimes ( 1 ) ;
257+ } ) ;
177258} ) ;
0 commit comments