Skip to content

Commit 8c29ecf

Browse files
authored
test(tracing): Add integration tests for pageload and navigation (#4376)
1 parent c1341fd commit 8c29ecf

File tree

6 files changed

+150
-0
lines changed

6 files changed

+150
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing()],
9+
tracesSampleRate: 1,
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="sentry-trace" content="12312012123120121231201212312012-1121201211212012-1" />
5+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
6+
</head>
7+
<body>
8+
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
9+
</body>
10+
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
6+
sentryTest(
7+
'should create a pageload transaction based on `sentry-trace` <meta>',
8+
async ({ getLocalTestPath, page }) => {
9+
const url = await getLocalTestPath({ testDir: __dirname });
10+
11+
const eventData = await getSentryTransactionRequest(page, url);
12+
13+
expect(eventData.contexts?.trace).toMatchObject({
14+
op: 'pageload',
15+
parent_span_id: '1121201211212012',
16+
trace_id: '12312012123120121231201212312012',
17+
});
18+
19+
expect(eventData.spans?.length).toBeGreaterThan(0);
20+
},
21+
);
22+
23+
sentryTest(
24+
"should create a navigation that's not influenced by `sentry-trace` <meta>",
25+
async ({ getLocalTestPath, page }) => {
26+
const url = await getLocalTestPath({ testDir: __dirname });
27+
28+
const pageloadRequest = await getSentryTransactionRequest(page, url);
29+
const navigationRequest = await getSentryTransactionRequest(page, `${url}#foo`);
30+
31+
expect(pageloadRequest.contexts?.trace).toMatchObject({
32+
op: 'pageload',
33+
parent_span_id: '1121201211212012',
34+
trace_id: '12312012123120121231201212312012',
35+
});
36+
37+
expect(navigationRequest.contexts?.trace.op).toBe('navigation');
38+
expect(navigationRequest.contexts?.trace.trace_id).toBeDefined();
39+
expect(navigationRequest.contexts?.trace.trace_id).not.toBe(pageloadRequest.contexts?.trace.trace_id);
40+
41+
const pageloadSpans = pageloadRequest.spans;
42+
const navigationSpans = navigationRequest.spans;
43+
44+
const pageloadSpanId = pageloadRequest.contexts?.trace.span_id;
45+
const navigationSpanId = navigationRequest.contexts?.trace.span_id;
46+
47+
expect(pageloadSpanId).toBeDefined();
48+
expect(navigationSpanId).toBeDefined();
49+
50+
pageloadSpans?.forEach(span =>
51+
expect(span).toMatchObject({
52+
parent_span_id: pageloadSpanId,
53+
}),
54+
);
55+
56+
navigationSpans?.forEach(span =>
57+
expect(span).toMatchObject({
58+
parent_span_id: navigationSpanId,
59+
}),
60+
);
61+
},
62+
);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should create a navigation transaction on page navigation', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const pageloadRequest = await getSentryTransactionRequest(page, url);
10+
const navigationRequest = await getSentryTransactionRequest(page, `${url}#foo`);
11+
12+
expect(pageloadRequest.contexts?.trace.op).toBe('pageload');
13+
expect(navigationRequest.contexts?.trace.op).toBe('navigation');
14+
15+
const pageloadTraceId = pageloadRequest.contexts?.trace.trace_id;
16+
const navigationTraceId = navigationRequest.contexts?.trace.trace_id;
17+
18+
expect(pageloadTraceId).toBeDefined();
19+
expect(navigationTraceId).toBeDefined();
20+
expect(pageloadTraceId).not.toEqual(navigationTraceId);
21+
22+
const pageloadSpans = pageloadRequest.spans;
23+
const navigationSpans = navigationRequest.spans;
24+
25+
const pageloadSpanId = pageloadRequest.contexts?.trace.span_id;
26+
const navigationSpanId = navigationRequest.contexts?.trace.span_id;
27+
28+
expect(pageloadSpanId).toBeDefined();
29+
expect(navigationSpanId).toBeDefined();
30+
31+
pageloadSpans?.forEach(span =>
32+
expect(span).toMatchObject({
33+
parent_span_id: pageloadSpanId,
34+
}),
35+
);
36+
37+
navigationSpans?.forEach(span =>
38+
expect(span).toMatchObject({
39+
parent_span_id: navigationSpanId,
40+
}),
41+
);
42+
43+
expect(pageloadSpanId).not.toEqual(navigationSpanId);
44+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { getSentryTransactionRequest } from '../../../../utils/helpers';
5+
6+
sentryTest('should create a pageload transaction', async ({ getLocalTestPath, page }) => {
7+
const url = await getLocalTestPath({ testDir: __dirname });
8+
9+
const eventData = await getSentryTransactionRequest(page, url);
10+
11+
expect(eventData.contexts?.trace?.op).toBe('pageload');
12+
expect(eventData.spans?.length).toBeGreaterThan(0);
13+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
<script src="{{htmlWebpackPlugin.options.initialization}}"></script>
7+
</head>
8+
<body>
9+
<script src="{{htmlWebpackPlugin.options.subject}}"></script>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)