From 08fe21ee9d70784bbeecb3c0e2507293d62b4ebd Mon Sep 17 00:00:00 2001 From: Luca Forstner Date: Fri, 17 Jan 2025 12:43:00 +0000 Subject: [PATCH] test(browser-integration-test): Fix flakey test --- .../suites/tracing/request/fetch/test.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts b/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts index bcbfa1890cdd..e1aca233ecf2 100644 --- a/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts +++ b/dev-packages/browser-integration-tests/suites/tracing/request/fetch/test.ts @@ -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()) { @@ -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(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');