Skip to content

Commit dcd9311

Browse files
committed
fix tests & add test for absolute url handling
1 parent cee11ea commit dcd9311

File tree

2 files changed

+70
-3
lines changed
  • dev-packages/browser-integration-tests/suites
    • integrations/Breadcrumbs/history/navigation
    • tracing/browserTracingIntegration/navigation

2 files changed

+70
-3
lines changed

dev-packages/browser-integration-tests/suites/integrations/Breadcrumbs/history/navigation/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ sentryTest('should record history changes as navigation breadcrumbs', async ({ g
2929
category: 'navigation',
3030
data: {
3131
from: '/bar?a=1#fragment',
32-
to: '[object Object]',
32+
to: '/[object%20Object]',
3333
},
3434
timestamp: expect.any(Number),
3535
},
3636
{
3737
category: 'navigation',
3838
data: {
39-
from: '[object Object]',
39+
from: '/[object%20Object]',
4040
to: '/bar?a=1#fragment',
4141
},
4242
timestamp: expect.any(Number),

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/navigation/test.ts

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
88
} from '@sentry/core';
99
import { sentryTest } from '../../../../utils/fixtures';
10-
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
10+
import {
11+
envelopeRequestParser,
12+
getFirstSentryEnvelopeRequest,
13+
shouldSkipTracingTest,
14+
waitForTransactionRequest,
15+
} from '../../../../utils/helpers';
1116

1217
sentryTest('should create a navigation transaction on page navigation', async ({ getLocalTestUrl, page }) => {
1318
if (shouldSkipTracingTest()) {
@@ -85,3 +90,65 @@ sentryTest('should create a navigation transaction on page navigation', async ({
8590

8691
expect(pageloadSpanId).not.toEqual(navigationSpanId);
8792
});
93+
94+
//
95+
sentryTest('should handle pushState with full URL', async ({ getLocalTestUrl, page }) => {
96+
if (shouldSkipTracingTest()) {
97+
sentryTest.skip();
98+
}
99+
100+
const url = await getLocalTestUrl({ testDir: __dirname });
101+
102+
const pageloadRequestPromise = waitForTransactionRequest(page, event => event.contexts?.trace?.op === 'pageload');
103+
const navigationRequestPromise = waitForTransactionRequest(
104+
page,
105+
event => event.contexts?.trace?.op === 'navigation' && event.transaction === '/sub-page',
106+
);
107+
const navigationRequestPromise2 = waitForTransactionRequest(
108+
page,
109+
event => event.contexts?.trace?.op === 'navigation' && event.transaction === '/sub-page-2',
110+
);
111+
112+
await page.goto(url);
113+
await pageloadRequestPromise;
114+
115+
await page.evaluate("window.history.pushState({}, '', `${window.location.origin}/sub-page`);");
116+
117+
const navigationRequest = envelopeRequestParser(await navigationRequestPromise);
118+
119+
expect(navigationRequest.transaction).toEqual('/sub-page');
120+
121+
expect(navigationRequest.contexts?.trace?.data).toMatchObject({
122+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser',
123+
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
124+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
125+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
126+
['sentry.idle_span_finish_reason']: 'idleTimeout',
127+
});
128+
expect(navigationRequest.request).toEqual({
129+
headers: {
130+
'User-Agent': expect.any(String),
131+
},
132+
url: 'http://sentry-test.io/sub-page',
133+
});
134+
135+
await page.evaluate("window.history.pushState({}, '', `${window.location.origin}/sub-page-2`);");
136+
137+
const navigationRequest2 = envelopeRequestParser(await navigationRequestPromise2);
138+
139+
expect(navigationRequest2.transaction).toEqual('/sub-page-2');
140+
141+
expect(navigationRequest2.contexts?.trace?.data).toMatchObject({
142+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.browser',
143+
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
144+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
145+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
146+
['sentry.idle_span_finish_reason']: 'idleTimeout',
147+
});
148+
expect(navigationRequest2.request).toEqual({
149+
headers: {
150+
'User-Agent': expect.any(String),
151+
},
152+
url: 'http://sentry-test.io/sub-page-2',
153+
});
154+
});

0 commit comments

Comments
 (0)