Skip to content

Commit 02b87eb

Browse files
committed
test(e2e): Add behaviour test for Errors in standard React E2E tests application
1 parent 28c464d commit 02b87eb

File tree

15 files changed

+925
-27
lines changed

15 files changed

+925
-27
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ jobs:
642642
- name: Run E2E tests
643643
env:
644644
E2E_TEST_PUBLISH_SCRIPT_NODE_VERSION: ${{ env.DEFAULT_NODE_VERSION }}
645+
E2E_TEST_AUTH_TOKEN: ${{ secrets.E2E_TEST_AUTH_TOKEN }}
645646
run: |
646647
cd packages/e2e-tests
647648
yarn test:e2e

packages/e2e-tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
auth-token.json

packages/e2e-tests/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"lint": "run-s lint:prettier lint:eslint",
1414
"lint:eslint": "eslint . --cache --cache-location '../../eslintcache/' --format stylish",
1515
"lint:prettier": "prettier --config ../../.prettierrc.json --check .",
16-
"test:e2e": "run-s test:validate-configuration test:test-app-setups test:run",
16+
"test:e2e": "run-s test:validate-configuration test:validate-test-app-setups test:validate-auth-token test:run",
1717
"test:run": "ts-node run.ts",
1818
"test:validate-configuration": "ts-node validate-verdaccio-configuration.ts",
19-
"test:test-app-setups": "ts-node validate-test-app-setups.ts"
19+
"test:validate-test-app-setups": "ts-node validate-test-app-setups.ts",
20+
"test:validate-auth-token": "ts-node validate-auth-token.ts"
2021
},
2122
"devDependencies": {
2223
"@types/glob": "8.0.0",

packages/e2e-tests/run.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,20 @@ const publishScriptNodeVersion = process.env.E2E_TEST_PUBLISH_SCRIPT_NODE_VERSIO
1616
const DEFAULT_BUILD_TIMEOUT_SECONDS = 60;
1717
const DEFAULT_TEST_TIMEOUT_SECONDS = 60;
1818

19+
let authToken = process.env.E2E_TEST_AUTH_TOKEN;
20+
21+
try {
22+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
23+
authToken = require(path.resolve(__dirname, 'auth-token.json')).authToken;
24+
} catch (e) {
25+
console.log('Failed to parse auth-token.json');
26+
}
27+
28+
if (!authToken) {
29+
console.log('No auth token configured!');
30+
process.exit(1);
31+
}
32+
1933
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines
2034
function groupCIOutput(groupTitle: string, fn: () => void): void {
2135
if (process.env.CI) {
@@ -176,6 +190,10 @@ const recipeResults: RecipeResult[] = recipePaths.map(recipePath => {
176190
cwd: path.dirname(recipePath),
177191
timeout: (test.timeoutSeconds ?? DEFAULT_TEST_TIMEOUT_SECONDS) * 1000,
178192
encoding: 'utf8',
193+
env: {
194+
...process.env,
195+
E2E_TEST_AUTH_TOKEN: authToken,
196+
},
179197
shell: true, // needed so we can pass the test command in as whole without splitting it up into args
180198
});
181199

packages/e2e-tests/test-applications/standard-frontend-react/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ yarn-debug.log*
2323
yarn-error.log*
2424

2525
!*.d.ts
26+
/test-results/
27+
/playwright-report/
28+
/playwright/.cache/

packages/e2e-tests/test-applications/standard-frontend-react/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
"web-vitals": "2.1.0"
2121
},
2222
"scripts": {
23-
"start": "react-scripts start",
24-
"build": "react-scripts build"
23+
"build": "react-scripts build",
24+
"start": "serve -s build",
25+
"test": "playwright test"
2526
},
2627
"eslintConfig": {
2728
"extends": [
@@ -40,5 +41,10 @@
4041
"last 1 firefox version",
4142
"last 1 safari version"
4243
]
44+
},
45+
"devDependencies": {
46+
"@playwright/test": "1.26.1",
47+
"axios": "1.1.2",
48+
"serve": "14.0.1"
4349
}
4450
}
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: 'dot',
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: 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+
}

packages/e2e-tests/test-applications/standard-frontend-react/src/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import Index from './pages/Index';
1515
import User from './pages/User';
1616

1717
Sentry.init({
18-
dsn: 'https://[email protected]/1337',
18+
// DSN belongs to "e2e-javascript-standard-frontend-react" project in "sentry-sdks" org
19+
dsn: 'https://[email protected]/4503941750587392',
1920
integrations: [
2021
new BrowserTracing({
2122
routingInstrumentation: Sentry.reactRouterV6Instrumentation(
@@ -39,10 +40,10 @@ Sentry.addGlobalEventProcessor(event => {
3940
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation')
4041
) {
4142
const eventId = event.event_id;
42-
// @ts-ignore
43-
window.recordedTransactions = window.recordedTransactions || [];
44-
// @ts-ignore
45-
window.recordedTransactions.push(eventId);
43+
if (eventId) {
44+
window.recordedTransactions = window.recordedTransactions || [];
45+
window.recordedTransactions.push(eventId);
46+
}
4647
}
4748

4849
return event;

packages/e2e-tests/test-applications/standard-frontend-react/src/pages/Index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const Index = () => {
1111
id="exception-button"
1212
onClick={() => {
1313
const eventId = Sentry.captureException(new Error('I am an error!'));
14-
// @ts-ignore
1514
window.capturedExceptionId = eventId;
1615
}}
1716
/>

packages/e2e-tests/test-applications/standard-frontend-react/test-recipe.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@
22
"$schema": "../../test-recipe-schema.json",
33
"testApplicationName": "standard-frontend-react",
44
"buildCommand": "yarn install && yarn build",
5-
"tests": []
5+
"tests": [
6+
{
7+
"testName": "Playwright tests",
8+
"testCommand": "yarn test"
9+
}
10+
]
611
}

0 commit comments

Comments
 (0)