Skip to content

Commit 29ac5f5

Browse files
Zen-cronicLms24
authored andcommitted
test(browser): Update the test app to include soft navigation action
1 parent 5d3c21b commit 29ac5f5

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

dev-packages/e2e-tests/test-applications/default-browser/public/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
<input type="button" value="Capture Exception" id="exception-button" />
1212

13+
<div id="navigation">
14+
15+
<a id="navigation-link" href="#navigation-target">Navigation Link</a>
16+
17+
<div id="navigation-target">Navigated Element</div>
18+
19+
</div>
20+
1321
<!-- The script tags for the bundled JavaScript files will be injected here by HtmlWebpackPlugin in build.mjs-->
1422
</body>
1523
</html>

dev-packages/e2e-tests/test-applications/default-browser/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ Sentry.init({
1212
document.getElementById('exception-button').addEventListener('click', () => {
1313
throw new Error('I am an error!');
1414
});
15+
16+
document.getElementById('navigation-link').addEventListener('click', () => {
17+
document.getElementById('navigation-target').scrollIntoView({ behavior: 'smooth' });
18+
});

dev-packages/e2e-tests/test-applications/default-browser/tests/errors.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForError } from '@sentry-internal/test-utils';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
33

44
test('captures an error', async ({ page }) => {
55
const errorEventPromise = waitForError('default-browser', event => {
@@ -28,3 +28,31 @@ test('captures an error', async ({ page }) => {
2828
span_id: expect.any(String),
2929
});
3030
});
31+
32+
test('sets correct transactionName', async ({ page }) => {
33+
const transactionPromise = waitForTransaction('default-browser', async transactionEvent => {
34+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
35+
});
36+
37+
const errorEventPromise = waitForError('default-browser', event => {
38+
return !event.type && event.exception?.values?.[0]?.value === 'I am an error!';
39+
});
40+
41+
await page.goto('/');
42+
const transactionEvent = await transactionPromise;
43+
44+
const exceptionButton = page.locator('id=exception-button');
45+
await exceptionButton.click();
46+
47+
const errorEvent = await errorEventPromise;
48+
49+
expect(errorEvent.exception?.values).toHaveLength(1);
50+
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!');
51+
52+
expect(errorEvent.transaction).toEqual('/');
53+
54+
expect(errorEvent.contexts?.trace).toEqual({
55+
trace_id: transactionEvent.contexts?.trace?.trace_id,
56+
span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''),
57+
});
58+
});

dev-packages/e2e-tests/test-applications/default-browser/tests/transactions.test.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,20 @@ test('sends a pageload transaction', async ({ page }) => {
1111
});
1212

1313
await page.goto('/');
14-
const transactionEvent = await transactionPromise;
1514

16-
const exceptionButton = page.locator('id=exception-button');
17-
await exceptionButton.click();
15+
const rootSpan = await transactionPromise;
1816

19-
const errorEvent = await errorEventPromise;
20-
21-
expect(errorEvent.exception?.values).toHaveLength(1);
22-
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!');
23-
24-
expect(errorEvent.transaction).toEqual('/');
25-
26-
expect(errorEvent.contexts?.trace).toEqual({
27-
trace_id: transactionEvent.contexts?.trace?.trace_id,
28-
span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''),
17+
expect(rootSpan).toMatchObject({
18+
contexts: {
19+
trace: {
20+
op: 'pageload',
21+
origin: 'auto.pageload.browser',
22+
},
23+
},
24+
transaction: '/',
25+
transaction_info: {
26+
source: 'url',
27+
},
2928
});
3029
});
3130

0 commit comments

Comments
 (0)