Skip to content

Commit 7607c1b

Browse files
committed
Add E2E tests.
1 parent 92f4463 commit 7607c1b

File tree

13 files changed

+460
-0
lines changed

13 files changed

+460
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*
24+
25+
/test-results/
26+
/playwright-report/
27+
/playwright/.cache/
28+
29+
!*.d.ts
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://127.0.0.1:4873
2+
@sentry-internal:registry=http://127.0.0.1:4873
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "react-router-6-cross-usage",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@sentry/react": "latest || *",
7+
"@types/react": "18.0.0",
8+
"@types/react-dom": "18.0.0",
9+
"express": "4.20.0",
10+
"react": "18.2.0",
11+
"react-dom": "18.2.0",
12+
"react-router-dom": "^6.28.0",
13+
"react-scripts": "5.0.1",
14+
"typescript": "~5.0.0"
15+
},
16+
"scripts": {
17+
"build": "react-scripts build",
18+
"start": "run-p start:client start:server",
19+
"start:client": "node server/app.js",
20+
"start:server": "serve -s build",
21+
"test": "playwright test",
22+
"clean": "npx rimraf node_modules pnpm-lock.yaml",
23+
"test:build": "pnpm install && npx playwright install && pnpm build",
24+
"test:build-ts3.8": "pnpm install && pnpm add [email protected] && npx playwright install && pnpm build",
25+
"test:build-canary": "pnpm install && pnpm add react@canary react-dom@canary && npx playwright install && pnpm build",
26+
"test:assert": "pnpm test"
27+
},
28+
"eslintConfig": {
29+
"extends": [
30+
"react-app",
31+
"react-app/jest"
32+
]
33+
},
34+
"browserslist": {
35+
"production": [
36+
">0.2%",
37+
"not dead",
38+
"not op_mini all"
39+
],
40+
"development": [
41+
"last 1 chrome version",
42+
"last 1 firefox version",
43+
"last 1 safari version"
44+
]
45+
},
46+
"devDependencies": {
47+
"@playwright/test": "~1.50.0",
48+
"@sentry-internal/test-utils": "link:../../../test-utils",
49+
"serve": "14.0.1",
50+
"npm-run-all2": "^6.2.0"
51+
},
52+
"volta": {
53+
"extends": "../../package.json"
54+
}
55+
}
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1" />
6+
<meta name="theme-color" content="#000000" />
7+
<meta name="description" content="Web site created using create-react-app" />
8+
<title>React App</title>
9+
</head>
10+
<body>
11+
<noscript>You need to enable JavaScript to run this app.</noscript>
12+
<div id="root"></div>
13+
<!--
14+
This HTML file is a template.
15+
If you open it directly in the browser, you will see an empty page.
16+
17+
You can add webfonts, meta tags, or analytics to this file.
18+
The build step will place the bundled scripts into the <body> tag.
19+
20+
To begin the development, run `npm start` or `yarn start`.
21+
To create a production bundle, use `npm run build` or `yarn build`.
22+
-->
23+
</body>
24+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const express = require('express');
2+
3+
const app = express();
4+
const PORT = 8080;
5+
6+
const wait = time => {
7+
return new Promise(resolve => {
8+
setTimeout(() => {
9+
resolve();
10+
}, time);
11+
});
12+
};
13+
14+
async function sseHandler(request, response, timeout = false) {
15+
response.headers = {
16+
'Content-Type': 'text/event-stream',
17+
Connection: 'keep-alive',
18+
'Cache-Control': 'no-cache',
19+
'Access-Control-Allow-Origin': '*',
20+
};
21+
22+
response.setHeader('Cache-Control', 'no-cache');
23+
response.setHeader('Content-Type', 'text/event-stream');
24+
response.setHeader('Access-Control-Allow-Origin', '*');
25+
response.setHeader('Connection', 'keep-alive');
26+
27+
response.flushHeaders();
28+
29+
await wait(2000);
30+
31+
for (let index = 0; index < 10; index++) {
32+
response.write(`data: ${new Date().toISOString()}\n\n`);
33+
if (timeout) {
34+
await wait(10000);
35+
}
36+
}
37+
38+
response.end();
39+
}
40+
41+
app.get('/sse', (req, res) => sseHandler(req, res));
42+
43+
app.get('/sse-timeout', (req, res) => sseHandler(req, res, true));
44+
45+
app.listen(PORT, () => {
46+
console.log(`SSE service listening at http://localhost:${PORT}`);
47+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface Window {
2+
recordedTransactions?: string[];
3+
capturedExceptionId?: string;
4+
sentryReplayId?: string;
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import * as Sentry from '@sentry/react';
2+
import React from 'react';
3+
import ReactDOM from 'react-dom/client';
4+
import {
5+
BrowserRouter,
6+
Outlet,
7+
Route,
8+
RouterProvider,
9+
Routes,
10+
createBrowserRouter,
11+
createRoutesFromChildren,
12+
matchRoutes,
13+
useLocation,
14+
useNavigationType,
15+
useRoutes,
16+
} from 'react-router-dom';
17+
import Index from './pages/Index';
18+
19+
const replay = Sentry.replayIntegration();
20+
21+
Sentry.init({
22+
environment: 'qa', // dynamic sampling bias to keep transactions
23+
dsn: process.env.REACT_APP_E2E_TEST_DSN,
24+
integrations: [
25+
Sentry.reactRouterV6BrowserTracingIntegration({
26+
useEffect: React.useEffect,
27+
useLocation,
28+
useNavigationType,
29+
createRoutesFromChildren,
30+
matchRoutes,
31+
trackFetchStreamPerformance: true,
32+
}),
33+
replay,
34+
],
35+
// We recommend adjusting this value in production, or using tracesSampler
36+
// for finer control
37+
tracesSampleRate: 1.0,
38+
release: 'e2e-test',
39+
40+
// Always capture replays, so we can test this properly
41+
replaysSessionSampleRate: 1.0,
42+
replaysOnErrorSampleRate: 0.0,
43+
44+
tunnel: 'http://localhost:3031',
45+
});
46+
47+
const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes);
48+
const sentryUseRoutes = Sentry.wrapUseRoutesV6(useRoutes);
49+
const sentryCreateBrowserRouter = Sentry.wrapCreateBrowserRouterV6(createBrowserRouter);
50+
51+
const DetailsRoutes = () =>
52+
sentryUseRoutes([
53+
{
54+
path: ':detailId',
55+
element: <div id="details">Details</div>,
56+
},
57+
]);
58+
59+
const DetailsRoutesAlternative = () => (
60+
<SentryRoutes>
61+
<Route path=":detailId" element={<div id="details">Details</div>} />
62+
</SentryRoutes>
63+
);
64+
65+
const ViewsRoutes = () =>
66+
sentryUseRoutes([
67+
{
68+
index: true,
69+
element: <div id="views">Views</div>,
70+
},
71+
{
72+
path: 'views/:viewId/*',
73+
element: <DetailsRoutes />,
74+
},
75+
{
76+
path: 'old-views/:viewId/*',
77+
element: <DetailsRoutesAlternative />,
78+
},
79+
]);
80+
81+
const ProjectsRoutes = () => (
82+
<SentryRoutes>
83+
<Route path="projects" element={<Outlet />}>
84+
<Route index element={<div>Project Page Root</div>} />
85+
<Route path="*" element={<Outlet />}>
86+
<Route path=":projectId/*" element={<ViewsRoutes />} />
87+
</Route>
88+
</Route>
89+
</SentryRoutes>
90+
);
91+
92+
const router = sentryCreateBrowserRouter([
93+
{
94+
children: [
95+
{
96+
path: '/',
97+
element: <Index />,
98+
},
99+
{
100+
path: '/*',
101+
element: <ProjectsRoutes />,
102+
},
103+
],
104+
},
105+
]);
106+
107+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
108+
root.render(<RouterProvider router={router} />);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
2+
import * as React from 'react';
3+
import { Link } from 'react-router-dom';
4+
5+
const Index = () => {
6+
return (
7+
<>
8+
<Link to="/projects/123/views/456/789" id="navigation">
9+
navigate
10+
</Link>
11+
<Link to="/projects/123/old-views/345/654" id="old-navigation">
12+
navigate old
13+
</Link>
14+
</>
15+
);
16+
};
17+
18+
export default Index;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />
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-cross-usage',
6+
});

0 commit comments

Comments
 (0)