-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathtest.ts
75 lines (62 loc) · 2.39 KB
/
test.ts
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
import { expect } from '@playwright/test';
import type { Event } from '@sentry/types';
import { sentryTest } from '../../../../utils/fixtures';
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
sentryTest('should create spans for XHR requests', async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestPath({ testDir: __dirname });
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
const requestSpans = eventData.spans?.filter(({ op }) => op === 'http.client');
expect(requestSpans).toHaveLength(3);
requestSpans?.forEach((span, index) =>
expect(span).toMatchObject({
description: `GET http://example.com/${index}`,
parent_span_id: eventData.contexts?.trace?.span_id,
span_id: expect.any(String),
start_timestamp: expect.any(Number),
timestamp: expect.any(Number),
trace_id: eventData.contexts?.trace?.trace_id,
data: {
'http.method': 'GET',
'http.url': `http://example.com/${index}`,
url: `http://example.com/${index}`,
'server.address': 'example.com',
type: 'xhr',
},
}),
);
});
sentryTest('should attach `sentry-trace` header to XHR requests', async ({ getLocalTestPath, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestPath({ testDir: __dirname });
const requests = (
await Promise.all([
page.goto(url),
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
])
)[1];
expect(requests).toHaveLength(3);
const request1 = requests[0];
const requestHeaders1 = request1.headers();
expect(requestHeaders1).toMatchObject({
'sentry-trace': expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})-1$/),
baggage: expect.any(String),
});
const request2 = requests[1];
const requestHeaders2 = request2.headers();
expect(requestHeaders2).toMatchObject({
'sentry-trace': expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})-1$/),
baggage: expect.any(String),
'x-test-header': 'existing-header',
});
const request3 = requests[2];
const requestHeaders3 = request3.headers();
expect(requestHeaders3).toMatchObject({
'sentry-trace': expect.stringMatching(/^([a-f0-9]{32})-([a-f0-9]{16})-1$/),
baggage: expect.any(String),
});
});