-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
93 lines (74 loc) · 2.95 KB
/
test.ts
File metadata and controls
93 lines (74 loc) · 2.95 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
83
84
85
86
87
88
89
90
91
92
93
import { expect } from '@playwright/test';
import type { Event, EventEnvelopeHeaders } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import {
envelopeHeaderRequestParser,
getFirstSentryEnvelopeRequest,
shouldSkipTracingTest,
} from '../../../../utils/helpers';
sentryTest(
'creates a pageload span based on `sentry-trace` <meta> without parent span id if parentlessRootSpans is true',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
const eventData = await getFirstSentryEnvelopeRequest<Event>(page, url);
expect(eventData.contexts?.trace).toMatchObject({
op: 'pageload',
trace_id: '12312012123120121231201212312012',
});
expect(eventData.contexts?.trace?.parent_span_id).toBeUndefined();
expect(eventData.spans?.length).toBeGreaterThan(0);
},
);
sentryTest(
'picks up `baggage` <meta> tag, propagate the content in transaction and not add own data',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
const envHeader = await getFirstSentryEnvelopeRequest<EventEnvelopeHeaders>(page, url, envelopeHeaderRequestParser);
expect(envHeader.trace).toBeDefined();
expect(envHeader.trace).toEqual({
release: '2.1.12',
sample_rate: '0.3232',
trace_id: '123',
public_key: 'public',
sample_rand: '0.42',
});
},
);
sentryTest("creates a navigation that's not influenced by `sentry-trace` <meta>", async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
const pageloadRequest = await getFirstSentryEnvelopeRequest<Event>(page, url);
const navigationRequest = await getFirstSentryEnvelopeRequest<Event>(page, `${url}#foo`);
expect(pageloadRequest.contexts?.trace).toMatchObject({
op: 'pageload',
trace_id: '12312012123120121231201212312012',
});
expect(pageloadRequest.contexts?.trace?.parent_span_id).toBeUndefined();
expect(navigationRequest.contexts?.trace?.op).toBe('navigation');
expect(navigationRequest.contexts?.trace?.trace_id).toBeDefined();
expect(navigationRequest.contexts?.trace?.trace_id).not.toBe(pageloadRequest.contexts?.trace?.trace_id);
const pageloadSpans = pageloadRequest.spans;
const navigationSpans = navigationRequest.spans;
const pageloadSpanId = pageloadRequest.contexts?.trace?.span_id;
const navigationSpanId = navigationRequest.contexts?.trace?.span_id;
expect(pageloadSpanId).toBeDefined();
expect(navigationSpanId).toBeDefined();
pageloadSpans?.forEach(span =>
expect(span).toMatchObject({
parent_span_id: pageloadSpanId,
}),
);
navigationSpans?.forEach(span =>
expect(span).toMatchObject({
parent_span_id: navigationSpanId,
}),
);
});