Skip to content

Commit 28c464d

Browse files
authored
test(e2e): Add standard frontend test app specification (#5874)
1 parent 29f4af1 commit 28c464d

File tree

12 files changed

+9375
-0
lines changed

12 files changed

+9375
-0
lines changed

packages/e2e-tests/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,44 @@ add Sentry dependencies to your test application, you should set the dependency
9393
```
9494

9595
All that is left for you to do now is to create a test app and run `yarn test:e2e`.
96+
97+
## Standardized Test Apps
98+
99+
For some of our E2E tests we define a standard for test applications as to how they should look and behave. Standardized
100+
test apps enables us to reuse the same test suite over a number of different frameworks/SDKs.
101+
102+
### Standardized Frontend Test Apps
103+
104+
A standardized frontend test application has the following features:
105+
106+
- Just for the sake of consistency we prefix the standardized frontend tests with `standard-frontend-`. For example
107+
`standard-frontend-nextjs`.
108+
- A page at path `/`
109+
- Having a `<input type="button" id="exception-button">` that captures an Exception when clicked. The returned
110+
`eventId` from the `Sentry.captureException()` call must be written to `window.capturedExceptionId`. It doesn not
111+
matter what the captured error looks like.
112+
- Having an link with `id="navigation"` that navigates to `/user/5`. It doesn't have to be an `<a>` tag, for example
113+
if a framework has another way of doing routing, the important part is that the element to click for navigation has
114+
the correct `id`. Text of the link doesn't matter.
115+
- An empty page at `/user/5`
116+
- Apps should write all pageload and navigation transaction IDs into an array at `window.recordedTransactions`. This can
117+
be done with an event processor:
118+
119+
```ts
120+
Sentry.addGlobalEventProcessor(event => {
121+
if (
122+
event.type === 'transaction' &&
123+
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')
124+
) {
125+
const eventId = event.event_id;
126+
window.recordedTransactions = window.recordedTransactions || [];
127+
window.recordedTransactions.push(eventId);
128+
}
129+
130+
return event;
131+
});
132+
```
133+
134+
### Standardized Backend Test Apps
135+
136+
TBD
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
!*.d.ts
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@sentry:registry=http://localhost:4873
2+
@sentry-internal:registry=http://localhost:4873
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "standard-frontend-react-test",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@sentry/react": "*",
7+
"@sentry/tracing": "*",
8+
"@testing-library/jest-dom": "5.14.1",
9+
"@testing-library/react": "13.0.0",
10+
"@testing-library/user-event": "13.2.1",
11+
"@types/jest": "27.0.1",
12+
"@types/node": "16.7.13",
13+
"@types/react": "18.0.0",
14+
"@types/react-dom": "18.0.0",
15+
"react": "18.2.0",
16+
"react-dom": "18.2.0",
17+
"react-router-dom": "^6.4.1",
18+
"react-scripts": "5.0.1",
19+
"typescript": "4.4.2",
20+
"web-vitals": "2.1.0"
21+
},
22+
"scripts": {
23+
"start": "react-scripts start",
24+
"build": "react-scripts build"
25+
},
26+
"eslintConfig": {
27+
"extends": [
28+
"react-app",
29+
"react-app/jest"
30+
]
31+
},
32+
"browserslist": {
33+
"production": [
34+
">0.2%",
35+
"not dead",
36+
"not op_mini all"
37+
],
38+
"development": [
39+
"last 1 chrome version",
40+
"last 1 firefox version",
41+
"last 1 safari version"
42+
]
43+
}
44+
}
Lines changed: 24 additions & 0 deletions
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>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import * as Sentry from '@sentry/react';
4+
import { BrowserTracing } from '@sentry/tracing';
5+
import {
6+
Routes,
7+
BrowserRouter,
8+
useLocation,
9+
useNavigationType,
10+
createRoutesFromChildren,
11+
matchRoutes,
12+
Route,
13+
} from 'react-router-dom';
14+
import Index from './pages/Index';
15+
import User from './pages/User';
16+
17+
Sentry.init({
18+
dsn: 'https://[email protected]/1337',
19+
integrations: [
20+
new BrowserTracing({
21+
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
22+
React.useEffect,
23+
useLocation,
24+
useNavigationType,
25+
createRoutesFromChildren,
26+
matchRoutes,
27+
),
28+
}),
29+
],
30+
// We recommend adjusting this value in production, or using tracesSampler
31+
// for finer control
32+
tracesSampleRate: 1.0,
33+
release: 'e2e-test',
34+
});
35+
36+
Sentry.addGlobalEventProcessor(event => {
37+
if (
38+
event.type === 'transaction' &&
39+
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')
40+
) {
41+
const eventId = event.event_id;
42+
// @ts-ignore
43+
window.recordedTransactions = window.recordedTransactions || [];
44+
// @ts-ignore
45+
window.recordedTransactions.push(eventId);
46+
}
47+
48+
return event;
49+
});
50+
51+
const SentryRoutes = Sentry.withSentryReactRouterV6Routing(Routes);
52+
53+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
54+
root.render(
55+
<BrowserRouter>
56+
<SentryRoutes>
57+
<Route path="/" element={<Index />} />
58+
<Route path="/user/:id" element={<User />} />
59+
</SentryRoutes>
60+
</BrowserRouter>,
61+
);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from 'react';
2+
import * as Sentry from '@sentry/react';
3+
import { Link } from 'react-router-dom';
4+
5+
const Index = () => {
6+
return (
7+
<>
8+
<input
9+
type="button"
10+
value="Capture Exception"
11+
id="exception-button"
12+
onClick={() => {
13+
const eventId = Sentry.captureException(new Error('I am an error!'));
14+
// @ts-ignore
15+
window.capturedExceptionId = eventId;
16+
}}
17+
/>
18+
<Link to="/user/5" id="navigation">
19+
navigate
20+
</Link>
21+
</>
22+
);
23+
};
24+
25+
export default Index;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as React from 'react';
2+
3+
const User = () => {
4+
return <p>I am a blank page :)</p>;
5+
};
6+
7+
export default User;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "../../test-recipe-schema.json",
3+
"testApplicationName": "standard-frontend-react",
4+
"buildCommand": "yarn install && yarn build",
5+
"tests": []
6+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"esModuleInterop": true,
8+
"allowSyntheticDefaultImports": true,
9+
"strict": true,
10+
"forceConsistentCasingInFileNames": true,
11+
"noFallthroughCasesInSwitch": true,
12+
"module": "esnext",
13+
"moduleResolution": "node",
14+
"resolveJsonModule": true,
15+
"isolatedModules": true,
16+
"noEmit": true,
17+
"jsx": "react"
18+
},
19+
"include": ["src"]
20+
}

0 commit comments

Comments
 (0)