-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
47 lines (40 loc) · 1.49 KB
/
Copy pathtest.ts
File metadata and controls
47 lines (40 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { envelopeUrlRegex, shouldSkipTracingTest } from '../../../../utils/helpers';
sentryTest(
'should not create span for fetch requests with no active span but should attach sentry-trace header',
async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestPath({ testDir: __dirname });
let requestCount = 0;
const sentryTraceHeaders: string[] = [];
page.on('request', request => {
const sentryTraceHeader = request.headers()['sentry-trace'];
if (sentryTraceHeader) {
sentryTraceHeaders.push(sentryTraceHeader);
}
expect(envelopeUrlRegex.test(request.url())).toBe(false);
requestCount++;
});
await page.goto(url);
// Here are the requests that should exist:
// 1. HTML page
// 2. Init JS bundle
// 3. Subject JS bundle
// 4 [OPTIONAl] CDN JS bundle
// and then 3 fetch requests
if (process.env.PW_BUNDLE && process.env.PW_BUNDLE.startsWith('bundle_')) {
expect(requestCount).toBe(7);
} else {
expect(requestCount).toBe(6);
}
expect(sentryTraceHeaders).toHaveLength(3);
expect(sentryTraceHeaders).toEqual([
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})$/),
]);
},
);