Skip to content

Commit e242ee6

Browse files
author
Luca Forstner
authored
test(e2e): Test building a create-react-app app with Sentry SDK (#5848)
1 parent 18cc680 commit e242ee6

29 files changed

+321
-50
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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
26+
yarn.lock
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "create-react-app-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-scripts": "5.0.1",
18+
"typescript": "4.4.2",
19+
"web-vitals": "2.1.0"
20+
},
21+
"scripts": {
22+
"start": "react-scripts start",
23+
"build": "react-scripts build",
24+
"test": "react-scripts test",
25+
"eject": "react-scripts eject"
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+
}
Binary file not shown.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta name="description" content="Web site created using create-react-app" />
9+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
10+
<!--
11+
manifest.json provides metadata used when your web app is installed on a
12+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
13+
-->
14+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
15+
<!--
16+
Notice the use of %PUBLIC_URL% in the tags above.
17+
It will be replaced with the URL of the `public` folder during the build.
18+
Only files inside the `public` folder can be referenced from the HTML.
19+
20+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
21+
work correctly both with client-side routing and a non-root public URL.
22+
Learn how to configure a non-root public URL by running `npm run build`.
23+
-->
24+
<title>React App</title>
25+
</head>
26+
<body>
27+
<noscript>You need to enable JavaScript to run this app.</noscript>
28+
<div id="root"></div>
29+
<!--
30+
This HTML file is a template.
31+
If you open it directly in the browser, you will see an empty page.
32+
33+
You can add webfonts, meta tags, or analytics to this file.
34+
The build step will place the bundled scripts into the <body> tag.
35+
36+
To begin the development, run `npm start` or `yarn start`.
37+
To create a production bundle, use `npm run build` or `yarn build`.
38+
-->
39+
</body>
40+
</html>
Loading
Loading
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.App {
2+
text-align: center;
3+
}
4+
5+
.App-logo {
6+
height: 40vmin;
7+
pointer-events: none;
8+
}
9+
10+
@media (prefers-reduced-motion: no-preference) {
11+
.App-logo {
12+
animation: App-logo-spin infinite 20s linear;
13+
}
14+
}
15+
16+
.App-header {
17+
background-color: #282c34;
18+
min-height: 100vh;
19+
display: flex;
20+
flex-direction: column;
21+
align-items: center;
22+
justify-content: center;
23+
font-size: calc(10px + 2vmin);
24+
color: white;
25+
}
26+
27+
.App-link {
28+
color: #61dafb;
29+
}
30+
31+
@keyframes App-logo-spin {
32+
from {
33+
transform: rotate(0deg);
34+
}
35+
to {
36+
transform: rotate(360deg);
37+
}
38+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import App from './App';
4+
5+
test('renders learn react link', () => {
6+
render(<App />);
7+
const linkElement = screen.getByText(/learn react/i);
8+
expect(linkElement).toBeInTheDocument();
9+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import React from 'react';
2+
import logo from './logo.svg';
3+
import * as Sentry from '@sentry/react';
4+
import './App.css';
5+
6+
function App() {
7+
return (
8+
<Sentry.ErrorBoundary
9+
fallback={({ error, componentStack, resetError }) => (
10+
<React.Fragment>
11+
<div>You have encountered an error</div>
12+
<div>{error.toString()}</div>
13+
<div>{componentStack}</div>
14+
<button
15+
onClick={() => {
16+
// When resetError() is called it will remove the Fallback component and render the Sentry ErrorBoundary's
17+
// children in their initial state
18+
resetError();
19+
}}
20+
>
21+
Click here to reset!
22+
</button>
23+
</React.Fragment>
24+
)}
25+
>
26+
<div className="App">
27+
<header className="App-header">
28+
<img src={logo} className="App-logo" alt="logo" />
29+
<p>
30+
Edit <code>src/App.tsx</code> and save to reload.
31+
</p>
32+
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer">
33+
Learn React
34+
</a>
35+
</header>
36+
<button
37+
onClick={() => {
38+
Sentry.captureException(new Error('I am a captured error!'));
39+
}}
40+
>
41+
I am capturing an error
42+
</button>
43+
</div>
44+
</Sentry.ErrorBoundary>
45+
);
46+
}
47+
48+
export default Sentry.withProfiler(App);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
body {
2+
margin: 0;
3+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans',
4+
'Droid Sans', 'Helvetica Neue', sans-serif;
5+
-webkit-font-smoothing: antialiased;
6+
-moz-osx-font-smoothing: grayscale;
7+
}
8+
9+
code {
10+
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', monospace;
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import './index.css';
4+
import App from './App';
5+
import reportWebVitals from './reportWebVitals';
6+
import * as Sentry from '@sentry/react';
7+
import { BrowserTracing } from '@sentry/tracing';
8+
9+
Sentry.init({
10+
dsn: 'https://[email protected]/1337',
11+
integrations: [new BrowserTracing()],
12+
13+
// We recommend adjusting this value in production, or using tracesSampler
14+
// for finer control
15+
tracesSampleRate: 1.0,
16+
});
17+
18+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
19+
root.render(
20+
<React.StrictMode>
21+
<App />
22+
</React.StrictMode>,
23+
);
24+
25+
// If you want to start measuring performance in your app, pass a function
26+
// to log results (for example: reportWebVitals(console.log))
27+
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
28+
reportWebVitals();
Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="react-scripts" />
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ReportHandler } from 'web-vitals';
2+
3+
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
4+
if (onPerfEntry && onPerfEntry instanceof Function) {
5+
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
6+
getCLS(onPerfEntry);
7+
getFID(onPerfEntry);
8+
getFCP(onPerfEntry);
9+
getLCP(onPerfEntry);
10+
getTTFB(onPerfEntry);
11+
});
12+
}
13+
};
14+
15+
export default reportWebVitals;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// jest-dom adds custom jest matchers for asserting on DOM nodes.
2+
// allows you to do things like:
3+
// expect(element).toHaveTextContent(/react/i)
4+
// learn more: https://github.com/testing-library/jest-dom
5+
import '@testing-library/jest-dom';
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": "create-react-app",
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+
}

packages/e2e-tests/test-applications/temporary-app-1/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/e2e-tests/test-applications/temporary-app-1/good.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/e2e-tests/test-applications/temporary-app-1/package.json

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

packages/e2e-tests/test-applications/temporary-app-1/test-recipe.json

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

packages/e2e-tests/test-applications/temporary-app-2/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/e2e-tests/test-applications/temporary-app-2/.npmrc

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

packages/e2e-tests/test-applications/temporary-app-2/good.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/e2e-tests/test-applications/temporary-app-2/package.json

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

packages/e2e-tests/test-applications/temporary-app-2/test-recipe.json

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

0 commit comments

Comments
 (0)