Skip to content

Commit

Permalink
test(v8/browser): Unflake browser request test (#15055)
Browse files Browse the repository at this point in the history
Backport of #15050

Co-authored-by: Francesco Gringl-Novy <francesco.novy@sentry.io>
  • Loading branch information
Lms24 and mydea authored Jan 17, 2025
1 parent 9ccf2bf commit 40d9b9f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { expect } from '@playwright/test';
import type { Event } from '@sentry/core';

import { sentryTest } from '../../../../utils/fixtures';
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers';
import {
envelopeRequestParser,
shouldSkipTracingTest,
waitForTransactionRequestOnUrl,
} from '../../../../utils/helpers';

sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
Expand All @@ -11,14 +13,8 @@ sentryTest('should create spans for fetch requests', async ({ getLocalTestUrl, p

const url = await getLocalTestUrl({ testDir: __dirname });

// Because we fetch from http://example.com, fetch will throw a CORS error in firefox and webkit.
// Chromium does not throw for cors errors.
// This means that we will intercept a dynamic amount of envelopes here.

// We will wait 500ms for all envelopes to be sent. Generally, in all browsers, the last sent
// envelope contains tracing data.
const envelopes = await getMultipleSentryEnvelopeRequests<Event>(page, 4, { url, timeout: 10000 });
const tracingEvent = envelopes.find(event => event.type === 'transaction')!; // last envelope contains tracing data on all browsers
const req = await waitForTransactionRequestOnUrl(page, url);
const tracingEvent = envelopeRequestParser(req);

const requestSpans = tracingEvent.spans?.filter(({ op }) => op === 'http.client');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ Sentry.init({
integrations: [Sentry.browserTracingIntegration()],
tracePropagationTargets: ['http://example.com'],
tracesSampleRate: 1,
autoSessionTracking: false,
});

0 comments on commit 40d9b9f

Please sign in to comment.