Skip to content

Commit d1978da

Browse files
committed
test(e2e): Update react-router-6 test to avoid sending to Sentry
1 parent 5dd4c63 commit d1978da

File tree

18 files changed

+138
-240
lines changed

18 files changed

+138
-240
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ jobs:
10121012
'react-create-hash-router',
10131013
'react-router-6-use-routes',
10141014
'react-router-5',
1015-
'standard-frontend-react',
1015+
'react-router-6',
10161016
'svelte-5',
10171017
'sveltekit',
10181018
'sveltekit-2',
@@ -1039,9 +1039,9 @@ jobs:
10391039
- test-application: 'create-react-app'
10401040
build-command: 'test:build-ts3.8'
10411041
label: 'create-react-app (TS 3.8)'
1042-
- test-application: 'standard-frontend-react'
1042+
- test-application: 'react-router-6'
10431043
build-command: 'test:build-ts3.8'
1044-
label: 'standard-frontend-react (TS 3.8)'
1044+
label: 'react-router-6 (TS 3.8)'
10451045
- test-application: 'create-next-app'
10461046
build-command: 'test:build-13'
10471047
label: 'create-next-app (next@13)'

.github/workflows/canary.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ jobs:
9292
- test-application: 'react-create-hash-router'
9393
build-command: 'test:build-canary'
9494
label: 'react-create-hash-router (canary)'
95-
- test-application: 'standard-frontend-react'
95+
- test-application: 'react-router-6'
9696
build-command: 'test:build-canary'
97-
label: 'standard-frontend-react (canary)'
97+
label: 'react-router-6 (canary)'
9898

9999
steps:
100100
- name: Check out current commit

dev-packages/e2e-tests/test-applications/standard-frontend-react/package.json renamed to dev-packages/e2e-tests/test-applications/react-router-6/package.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
{
2-
"name": "standard-frontend-react-test",
2+
"name": "react-router-6-test",
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
66
"@sentry/react": "latest || *",
7-
"@testing-library/jest-dom": "5.14.1",
8-
"@testing-library/react": "13.0.0",
9-
"@testing-library/user-event": "13.2.1",
10-
"@types/jest": "27.0.1",
11-
"@types/node": "16.7.13",
127
"@types/react": "18.0.0",
138
"@types/react-dom": "18.0.0",
149
"react": "18.2.0",
1510
"react-dom": "18.2.0",
1611
"react-router-dom": "^6.4.1",
1712
"react-scripts": "5.0.1",
18-
"typescript": "4.9.5",
19-
"web-vitals": "2.1.0"
13+
"typescript": "4.9.5"
2014
},
2115
"scripts": {
2216
"build": "react-scripts build",
@@ -48,6 +42,7 @@
4842
},
4943
"devDependencies": {
5044
"@playwright/test": "^1.44.1",
45+
"@sentry-internal/test-utils": "link:../../../test-utils",
5146
"serve": "14.0.1"
5247
},
5348
"volta": {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { getPlaywrightConfig } from '@sentry-internal/test-utils';
2+
3+
const config = getPlaywrightConfig({
4+
startCommand: `pnpm start`,
5+
});
6+
7+
export default config;

dev-packages/e2e-tests/test-applications/standard-frontend-react/src/index.tsx renamed to dev-packages/e2e-tests/test-applications/react-router-6/src/index.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,8 @@ Sentry.init({
3636
// Always capture replays, so we can test this properly
3737
replaysSessionSampleRate: 1.0,
3838
replaysOnErrorSampleRate: 0.0,
39-
});
40-
41-
Sentry.addEventProcessor(event => {
42-
if (
43-
event.type === 'transaction' &&
44-
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')
45-
) {
46-
const eventId = event.event_id;
47-
if (eventId) {
48-
window.recordedTransactions = window.recordedTransactions || [];
49-
window.recordedTransactions.push(eventId);
50-
}
51-
}
5239

53-
return event;
40+
tunnel: 'http://localhost:3031',
5441
});
5542

5643
const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes);

dev-packages/e2e-tests/test-applications/standard-frontend-react/src/pages/Index.tsx renamed to dev-packages/e2e-tests/test-applications/react-router-6/src/pages/Index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as Sentry from '@sentry/react';
21
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
32
import * as React from 'react';
43
import { Link } from 'react-router-dom';
@@ -11,8 +10,7 @@ const Index = () => {
1110
value="Capture Exception"
1211
id="exception-button"
1312
onClick={() => {
14-
const eventId = Sentry.captureException(new Error('I am an error!'));
15-
window.capturedExceptionId = eventId;
13+
throw new Error('I am an error!');
1614
}}
1715
/>
1816
<Link to="/user/5" id="navigation">
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { startEventProxyServer } from '@sentry-internal/test-utils';
2+
3+
startEventProxyServer({
4+
port: 3031,
5+
proxyServerName: 'react-router-6',
6+
});
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('Sends correct error event', async ({ page }) => {
5+
const errorEventPromise = waitForError('react-router-6', event => {
6+
return !event.type && event.exception?.values?.[0]?.value === 'I am an error!';
7+
});
8+
9+
await page.goto('/');
10+
11+
const exceptionButton = page.locator('id=exception-button');
12+
await exceptionButton.click();
13+
14+
const errorEvent = await errorEventPromise;
15+
16+
expect(errorEvent.exception?.values).toHaveLength(1);
17+
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!');
18+
19+
expect(errorEvent.request).toEqual({
20+
headers: expect.any(Object),
21+
url: 'http://localhost:3030/',
22+
});
23+
24+
expect(errorEvent.transaction).toEqual('/');
25+
26+
expect(errorEvent.contexts?.trace).toEqual({
27+
trace_id: expect.any(String),
28+
span_id: expect.any(String),
29+
});
30+
});
31+
32+
test('Sets correct transactionName', async ({ page }) => {
33+
const transactionPromise = waitForTransaction('react-router-6', async transactionEvent => {
34+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
35+
});
36+
37+
const errorEventPromise = waitForError('react-router-6', 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+
// Only capture error once transaction was sent
45+
const exceptionButton = page.locator('id=exception-button');
46+
await exceptionButton.click();
47+
48+
const errorEvent = await errorEventPromise;
49+
50+
expect(errorEvent.exception?.values).toHaveLength(1);
51+
expect(errorEvent.exception?.values?.[0]?.value).toBe('I am an error!');
52+
53+
expect(errorEvent.transaction).toEqual('/');
54+
55+
expect(errorEvent.contexts?.trace).toEqual({
56+
trace_id: transactionEvent.contexts?.trace?.trace_id,
57+
span_id: expect.not.stringContaining(transactionEvent.contexts?.trace?.span_id || ''),
58+
});
59+
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('sends a pageload transaction with a parameterized URL', async ({ page }) => {
5+
const transactionPromise = waitForTransaction('react-router-6', async transactionEvent => {
6+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
7+
});
8+
9+
await page.goto(`/`);
10+
11+
const rootSpan = await transactionPromise;
12+
13+
expect(rootSpan).toMatchObject({
14+
contexts: {
15+
trace: {
16+
op: 'pageload',
17+
origin: 'auto.pageload.react.reactrouter_v6',
18+
},
19+
},
20+
transaction: '/',
21+
transaction_info: {
22+
source: 'route',
23+
},
24+
});
25+
});
26+
27+
test('sends a navigation transaction with a parameterized URL', async ({ page }) => {
28+
page.on('console', msg => console.log(msg.text()));
29+
const pageloadTxnPromise = waitForTransaction('react-router-6', async transactionEvent => {
30+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'pageload';
31+
});
32+
33+
const navigationTxnPromise = waitForTransaction('react-router-6', async transactionEvent => {
34+
return !!transactionEvent?.transaction && transactionEvent.contexts?.trace?.op === 'navigation';
35+
});
36+
37+
await page.goto(`/`);
38+
await pageloadTxnPromise;
39+
40+
const linkElement = page.locator('id=navigation');
41+
42+
const [_, navigationTxn] = await Promise.all([linkElement.click(), navigationTxnPromise]);
43+
44+
expect(navigationTxn).toMatchObject({
45+
contexts: {
46+
trace: {
47+
op: 'navigation',
48+
origin: 'auto.navigation.react.reactrouter_v6',
49+
},
50+
},
51+
transaction: '/user/:id',
52+
transaction_info: {
53+
source: 'route',
54+
},
55+
});
56+
});

dev-packages/e2e-tests/test-applications/standard-frontend-react/playwright.config.ts

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)