1
1
import { expect } from '@playwright/test' ;
2
- import type { Event } from '@sentry/core' ;
3
-
4
2
import { sentryTest } from '../../../../utils/fixtures' ;
5
- import { getMultipleSentryEnvelopeRequests , shouldSkipTracingTest } from '../../../../utils/helpers' ;
3
+ import {
4
+ envelopeRequestParser ,
5
+ shouldSkipTracingTest ,
6
+ waitForTransactionRequestOnUrl ,
7
+ } from '../../../../utils/helpers' ;
6
8
7
9
sentryTest ( 'should create spans for fetch requests' , async ( { getLocalTestUrl, page } ) => {
8
10
if ( shouldSkipTracingTest ( ) ) {
@@ -11,14 +13,8 @@ sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, p
11
13
12
14
const url = await getLocalTestUrl ( { testDir : __dirname } ) ;
13
15
14
- // Because we fetch from http://example.com, fetch will throw a CORS error in firefox and webkit.
15
- // Chromium does not throw for cors errors.
16
- // This means that we will intercept a dynamic amount of envelopes here.
17
-
18
- // We will wait 500ms for all envelopes to be sent. Generally, in all browsers, the last sent
19
- // envelope contains tracing data.
20
- const envelopes = await getMultipleSentryEnvelopeRequests < Event > ( page , 4 , { url, timeout : 10000 } ) ;
21
- const tracingEvent = envelopes . find ( event => event . type === 'transaction' ) ! ; // last envelope contains tracing data on all browsers
16
+ const req = await waitForTransactionRequestOnUrl ( page , url ) ;
17
+ const tracingEvent = envelopeRequestParser ( req ) ;
22
18
23
19
const requestSpans = tracingEvent . spans ?. filter ( ( { op } ) => op === 'http.client' ) ;
24
20
0 commit comments