Skip to content

Commit a7c2c80

Browse files
committed
fix flaky test
1 parent 01f20e5 commit a7c2c80

File tree

2 files changed

+29
-15
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span

2 files changed

+29
-15
lines changed

dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/init.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ window.Sentry = Sentry;
44

55
Sentry.init({
66
dsn: 'https://[email protected]/1337',
7-
// disable pageload transaction
8-
integrations: [Sentry.browserTracingIntegration({ instrumentPageLoad: false })],
7+
// disable auto span creation
8+
integrations: [
9+
Sentry.browserTracingIntegration({
10+
instrumentPageLoad: false,
11+
instrumentNavigation: false,
12+
}),
13+
],
914
tracePropagationTargets: ['http://example.com'],
1015
tracesSampleRate: 1,
1116
});

dev-packages/browser-integration-tests/suites/tracing/request/fetch-with-no-active-span/test.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { sentryTest } from '../../../../utils/fixtures';
44
import { envelopeUrlRegex, shouldSkipTracingTest } from '../../../../utils/helpers';
55

66
sentryTest(
7-
'there should be no span created for fetch requests with no active span',
7+
'should not create span for fetch requests with no active span but should attach sentry-trace header',
88
async ({ getLocalTestPath, page }) => {
99
if (shouldSkipTracingTest()) {
1010
sentryTest.skip();
@@ -13,23 +13,32 @@ sentryTest(
1313
const url = await getLocalTestPath({ testDir: __dirname });
1414

1515
let requestCount = 0;
16+
const sentryTraceHeaders: string[] = [];
1617
page.on('request', request => {
17-
expect(envelopeUrlRegex.test(request.url())).toBe(false);
18+
const url = request.url();
19+
20+
const sentryTraceHeader = request.headers()['sentry-trace'];
21+
if (sentryTraceHeader) {
22+
sentryTraceHeaders.push(sentryTraceHeader);
23+
}
24+
expect(envelopeUrlRegex.test(url)).toBe(false);
25+
26+
// We only want to count API requests
27+
if (url.endsWith('.html') || url.endsWith('.js') || url.endsWith('.css') || url.endsWith('.map')) {
28+
return;
29+
}
1830
requestCount++;
1931
});
2032

2133
await page.goto(url);
2234

23-
// Here are the requests that should exist:
24-
// 1. HTML page
25-
// 2. Init JS bundle
26-
// 3. Subject JS bundle
27-
// 4 [OPTIONAl] CDN JS bundle
28-
// and then 3 fetch requests
29-
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
30-
expect(requestCount).toBe(7);
31-
} else {
32-
expect(requestCount).toBe(6);
33-
}
35+
expect(requestCount).toBe(3);
36+
37+
expect(sentryTraceHeaders).toHaveLength(3);
38+
expect(sentryTraceHeaders).toEqual([
39+
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
40+
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
41+
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
42+
]);
3443
},
3544
);

0 commit comments

Comments
 (0)