-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
82 lines (71 loc) · 2.11 KB
/
test.ts
File metadata and controls
82 lines (71 loc) · 2.11 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type { Page, Request } from '@playwright/test';
import { expect } from '@playwright/test';
import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../utils/helpers';
async function assertRequests({
page,
buttonSelector,
requestMatcher,
}: {
page: Page;
buttonSelector: string;
requestMatcher: string;
}) {
const requests = await new Promise<Request[]>(resolve => {
const requests: Request[] = [];
page
.route(requestMatcher, (route, request) => {
requests.push(request);
if (requests.length === 2) {
resolve(requests);
}
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({}),
});
})
.then(() => {
page.click(buttonSelector);
});
});
expect(requests).toHaveLength(2);
requests.forEach(request => {
const headers = request.headers();
// No merged sentry trace headers
expect(headers['sentry-trace']).not.toContain(',');
// No multiple baggage entries
expect(headers['baggage'].match(/sentry-release/g) ?? []).toHaveLength(1);
});
}
sentryTest(
'Ensure the SDK does not infinitely append tracing headers to outgoing requests',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
await sentryTest.step('fetch with POJO', () =>
assertRequests({
page,
buttonSelector: '#fetchPojo',
requestMatcher: 'http://sentry-test-site.example/fetch-pojo',
}),
);
await sentryTest.step('fetch with array', () =>
assertRequests({
page,
buttonSelector: '#fetchArray',
requestMatcher: 'http://sentry-test-site.example/fetch-array',
}),
);
await sentryTest.step('fetch with Headers instance', () =>
assertRequests({
page,
buttonSelector: '#fetchHeaders',
requestMatcher: 'http://sentry-test-site.example/fetch-headers',
}),
);
},
);