Skip to content

Commit c4fbb1f

Browse files
authored
test(e2e): Add E2E test with & without @sentry/tracing import (#7590)
1 parent a818cc7 commit c4fbb1f

File tree

16 files changed

+9821
-3
lines changed

16 files changed

+9821
-3
lines changed
Lines changed: 29 additions & 0 deletions
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
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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"name": "standard-frontend-react-tracing-import-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+
"build": "react-scripts build",
24+
"start": "serve -s build",
25+
"test": "playwright test"
26+
},
27+
"eslintConfig": {
28+
"extends": [
29+
"react-app",
30+
"react-app/jest"
31+
]
32+
},
33+
"browserslist": {
34+
"production": [
35+
">0.2%",
36+
"not dead",
37+
"not op_mini all"
38+
],
39+
"development": [
40+
"last 1 chrome version",
41+
"last 1 firefox version",
42+
"last 1 safari version"
43+
]
44+
},
45+
"devDependencies": {
46+
"@playwright/test": "1.26.1",
47+
"axios": "1.1.2",
48+
"serve": "14.0.1"
49+
}
50+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import type { PlaywrightTestConfig } from '@playwright/test';
2+
import { devices } from '@playwright/test';
3+
4+
/**
5+
* See https://playwright.dev/docs/test-configuration.
6+
*/
7+
const config: PlaywrightTestConfig = {
8+
testDir: './tests',
9+
/* Maximum time one test can run for. */
10+
timeout: 60 * 1000,
11+
expect: {
12+
/**
13+
* Maximum time expect() should wait for the condition to be met.
14+
* For example in `await expect(locator).toHaveText();`
15+
*/
16+
timeout: 5000,
17+
},
18+
/* Run tests in files in parallel */
19+
fullyParallel: true,
20+
/* Fail the build on CI if you accidentally left test.only in the source code. */
21+
forbidOnly: !!process.env.CI,
22+
/* Retry on CI only */
23+
retries: 0,
24+
/* Opt out of parallel tests on CI. */
25+
workers: 1,
26+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
27+
reporter: 'list',
28+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
29+
use: {
30+
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
31+
actionTimeout: 0,
32+
/* Base URL to use in actions like `await page.goto('/')`. */
33+
// baseURL: 'http://localhost:3000',
34+
35+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
36+
trace: 'on-first-retry',
37+
},
38+
39+
/* Configure projects for major browsers */
40+
projects: [
41+
{
42+
name: 'chromium',
43+
use: {
44+
...devices['Desktop Chrome'],
45+
},
46+
},
47+
// For now we only test Chrome!
48+
// {
49+
// name: 'firefox',
50+
// use: {
51+
// ...devices['Desktop Firefox'],
52+
// },
53+
// },
54+
// {
55+
// name: 'webkit',
56+
// use: {
57+
// ...devices['Desktop Safari'],
58+
// },
59+
// },
60+
],
61+
62+
/* Run your local dev server before starting the tests */
63+
webServer: {
64+
command: 'yarn start',
65+
port: 3000,
66+
},
67+
};
68+
69+
export default config;
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface Window {
2+
recordedTransactions?: string[];
3+
capturedExceptionId?: string;
4+
}
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: process.env.REACT_APP_E2E_TEST_DSN,
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+
if (eventId) {
43+
window.recordedTransactions = window.recordedTransactions || [];
44+
window.recordedTransactions.push(eventId);
45+
}
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
window.capturedExceptionId = eventId;
15+
}}
16+
/>
17+
<Link to="/user/5" id="navigation">
18+
navigate
19+
</Link>
20+
</>
21+
);
22+
};
23+
24+
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "../../test-recipe-schema.json",
3+
"testApplicationName": "standard-frontend-react-tracing-import",
4+
"buildCommand": "yarn install --pure-lockfile && npx playwright install && yarn build",
5+
"tests": [
6+
{
7+
"testName": "Playwright tests",
8+
"testCommand": "yarn test"
9+
}
10+
],
11+
"canaryVersions": []
12+
}

0 commit comments

Comments
 (0)