-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(e2e): Add behaviour test for Errors in standard React E2E tests …
…application (#5909)
- Loading branch information
Showing
14 changed files
with
474 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
E2E_TEST_AUTH_TOKEN= | ||
E2E_TEST_DSN= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,8 @@ npm-debug.log* | |
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/test-results/ | ||
/playwright-report/ | ||
/playwright/.cache/ | ||
|
||
!*.d.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/e2e-tests/test-applications/standard-frontend-react/playwright.config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { PlaywrightTestConfig } from '@playwright/test'; | ||
import { devices } from '@playwright/test'; | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
const config: PlaywrightTestConfig = { | ||
testDir: './tests', | ||
/* Maximum time one test can run for. */ | ||
timeout: 60 * 1000, | ||
expect: { | ||
/** | ||
* Maximum time expect() should wait for the condition to be met. | ||
* For example in `await expect(locator).toHaveText();` | ||
*/ | ||
timeout: 5000, | ||
}, | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: 1, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: 'dot', | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */ | ||
actionTimeout: 0, | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
// baseURL: 'http://localhost:3000', | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: 'on-first-retry', | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: 'chromium', | ||
use: { | ||
...devices['Desktop Chrome'], | ||
}, | ||
}, | ||
// For now we only test Chrome! | ||
// { | ||
// name: 'firefox', | ||
// use: { | ||
// ...devices['Desktop Firefox'], | ||
// }, | ||
// }, | ||
// { | ||
// name: 'webkit', | ||
// use: { | ||
// ...devices['Desktop Safari'], | ||
// }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: 'yarn start', | ||
port: 3000, | ||
}, | ||
}; | ||
|
||
export default config; |
4 changes: 4 additions & 0 deletions
4
packages/e2e-tests/test-applications/standard-frontend-react/src/globals.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
interface Window { | ||
recordedTransactions?: string[]; | ||
capturedExceptionId?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ import Index from './pages/Index'; | |
import User from './pages/User'; | ||
|
||
Sentry.init({ | ||
dsn: 'https://[email protected]/1337', | ||
dsn: process.env.REACT_APP_E2E_TEST_DSN, | ||
integrations: [ | ||
new BrowserTracing({ | ||
routingInstrumentation: Sentry.reactRouterV6Instrumentation( | ||
|
@@ -39,10 +39,10 @@ Sentry.addGlobalEventProcessor(event => { | |
(event.contexts?.trace?.op === 'pageload' || event.contexts?.trace?.op === 'navigation') | ||
) { | ||
const eventId = event.event_id; | ||
// @ts-ignore | ||
window.recordedTransactions = window.recordedTransactions || []; | ||
// @ts-ignore | ||
window.recordedTransactions.push(eventId); | ||
if (eventId) { | ||
window.recordedTransactions = window.recordedTransactions || []; | ||
window.recordedTransactions.push(eventId); | ||
} | ||
} | ||
|
||
return event; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
packages/e2e-tests/test-applications/standard-frontend-react/test-recipe.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
{ | ||
"$schema": "../../test-recipe-schema.json", | ||
"testApplicationName": "standard-frontend-react", | ||
"buildCommand": "yarn install && yarn build", | ||
"tests": [] | ||
"buildCommand": "yarn install --pure-lockfile && npx playwright install && yarn build", | ||
"tests": [ | ||
{ | ||
"testName": "Playwright tests", | ||
"testCommand": "yarn test" | ||
} | ||
] | ||
} |
47 changes: 47 additions & 0 deletions
47
packages/e2e-tests/test-applications/standard-frontend-react/tests/behaviour-test.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { test, expect } from '@playwright/test'; | ||
import axios, { AxiosError } from 'axios'; | ||
|
||
const SENTRY_TEST_ORG_SLUG = 'sentry-sdks'; | ||
const SENTRY_TEST_PROJECT = 'sentry-javascript-e2e-tests'; | ||
|
||
const EVENT_POLLING_TIMEOUT = 45000; | ||
const EVENT_POLLING_RETRY_INTERVAL = 1000; | ||
|
||
const authToken = process.env.E2E_TEST_AUTH_TOKEN; | ||
|
||
test('Sends an exception to Sentry', async ({ page }) => { | ||
await page.goto('/'); | ||
|
||
const exceptionButton = page.locator('id=exception-button'); | ||
await exceptionButton.click(); | ||
|
||
const exceptionIdHandle = await page.waitForFunction(() => window.capturedExceptionId); | ||
const exceptionEventId = await exceptionIdHandle.jsonValue(); | ||
|
||
let lastErrorResponse: AxiosError | undefined; | ||
|
||
const timeout = setTimeout(() => { | ||
if (lastErrorResponse?.response?.status) { | ||
throw new Error( | ||
`Timeout reached while polling event. Last received status code: ${lastErrorResponse.response.status}`, | ||
); | ||
} else { | ||
throw new Error('Timeout reached while polling event.'); | ||
} | ||
}, EVENT_POLLING_TIMEOUT); | ||
|
||
while (true) { | ||
try { | ||
const response = await axios.get( | ||
`https://sentry.io/api/0/projects/${SENTRY_TEST_ORG_SLUG}/${SENTRY_TEST_PROJECT}/events/${exceptionEventId}/`, | ||
{ headers: { Authorization: `Bearer ${authToken}` } }, | ||
); | ||
clearTimeout(timeout); | ||
expect(response?.status).toBe(200); | ||
break; | ||
} catch (e) { | ||
lastErrorResponse = e; | ||
await new Promise(resolve => setTimeout(resolve, EVENT_POLLING_RETRY_INTERVAL)); | ||
} | ||
} | ||
}); |
Oops, something went wrong.