File tree Expand file tree Collapse file tree 9 files changed +208
-482
lines changed
dev-packages/e2e-tests/test-applications/react-create-hash-router Expand file tree Collapse file tree 9 files changed +208
-482
lines changed Original file line number Diff line number Diff line change 4646 ]
4747 },
4848 "devDependencies" : {
49+ "@sentry-internal/event-proxy-server" : " link:../../../event-proxy-server" ,
4950 "@playwright/test" : " 1.26.1" ,
5051 "serve" : " 14.0.1"
5152 },
Original file line number Diff line number Diff line change 1- import type { PlaywrightTestConfig } from '@playwright/test' ;
21import { devices } from '@playwright/test' ;
32
3+ const serverPort = 3030 ;
4+ const eventProxyPort = 3031 ;
5+
46/**
57 * See https://playwright.dev/docs/test-configuration.
68 */
7- const config : PlaywrightTestConfig = {
9+ const config = {
810 testDir : './tests' ,
911 /* Maximum time one test can run for. */
1012 timeout : 150_000 ,
@@ -32,6 +34,9 @@ const config: PlaywrightTestConfig = {
3234
3335 /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
3436 trace : 'on-first-retry' ,
37+
38+ /* Base URL to use in actions like `await page.goto('/')`. */
39+ baseURL : `http://localhost:${ serverPort } ` ,
3540 } ,
3641
3742 /* Configure projects for major browsers */
@@ -58,13 +63,19 @@ const config: PlaywrightTestConfig = {
5863 ] ,
5964
6065 /* Run your local dev server before starting the tests */
61- webServer : {
62- command : 'pnpm start' ,
63- port : 3030 ,
64- env : {
65- PORT : '3030' ,
66+ webServer : [
67+ {
68+ command : 'node start-event-proxy.mjs' ,
69+ port : eventProxyPort ,
6670 } ,
67- } ,
71+ {
72+ command : 'pnpm start' ,
73+ port : serverPort ,
74+ env : {
75+ PORT : '3030' ,
76+ } ,
77+ } ,
78+ ] ,
6879} ;
6980
7081export default config ;
Original file line number Diff line number Diff line change @@ -32,34 +32,15 @@ Sentry.init({
3232 tracesSampleRate : 1.0 ,
3333 release : 'e2e-test' ,
3434
35+ tunnel : 'http://localhost:3031' ,
36+
3537 // Always capture replays, so we can test this properly
3638 replaysSessionSampleRate : 1.0 ,
3739 replaysOnErrorSampleRate : 0.0 ,
3840
3941 debug : true ,
4042} ) ;
4143
42- Object . defineProperty ( window , 'sentryReplayId' , {
43- get ( ) {
44- return replay [ '_replay' ] . session . id ;
45- } ,
46- } ) ;
47-
48- Sentry . addEventProcessor ( event => {
49- if (
50- event . type === 'transaction' &&
51- ( event . contexts ?. trace ?. op === 'pageload' || event . contexts ?. trace ?. op === 'navigation' )
52- ) {
53- const eventId = event . event_id ;
54- if ( eventId ) {
55- window . recordedTransactions = window . recordedTransactions || [ ] ;
56- window . recordedTransactions . push ( eventId ) ;
57- }
58- }
59-
60- return event ;
61- } ) ;
62-
6344const sentryCreateHashRouter = Sentry . wrapCreateBrowserRouter ( createHashRouter ) ;
6445
6546const router = sentryCreateHashRouter ( [
Original file line number Diff line number Diff line change 1- import * as Sentry from '@sentry/react' ;
21// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
32import * as React from 'react' ;
43import { Link } from 'react-router-dom' ;
@@ -11,8 +10,7 @@ const Index = () => {
1110 value = "Capture Exception"
1211 id = "exception-button"
1312 onClick = { ( ) => {
14- const eventId = Sentry . captureException ( new Error ( 'I am an error!' ) ) ;
15- window . capturedExceptionId = eventId ;
13+ throw new Error ( 'I am an error!' ) ;
1614 } }
1715 />
1816 < Link to = "/user/5" id = "navigation" >
Original file line number Diff line number Diff line change 1+ import { startEventProxyServer } from '@sentry-internal/event-proxy-server' ;
2+
3+ startEventProxyServer ( {
4+ port : 3031 ,
5+ proxyServerName : 'react-create-hash-router' ,
6+ } ) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ import { expect , test } from '@playwright/test' ;
2+ import { waitForError } from '@sentry-internal/event-proxy-server' ;
3+
4+ test ( 'Captures exception correctly' , async ( { page } ) => {
5+ const errorEventPromise = waitForError ( 'react-create-hash-router' , event => {
6+ return ! event . type && event . exception ?. values ?. [ 0 ] ?. value === 'I am an error!' ;
7+ } ) ;
8+
9+ await page . goto ( '/' ) ;
10+
11+ const exceptionButton = page . locator ( 'id=exception-button' ) ;
12+ await exceptionButton . click ( ) ;
13+
14+ const errorEvent = await errorEventPromise ;
15+
16+ expect ( errorEvent . exception ?. values ) . toHaveLength ( 1 ) ;
17+ expect ( errorEvent . exception ?. values ?. [ 0 ] ?. value ) . toBe ( 'I am an error!' ) ;
18+
19+ expect ( errorEvent . request ) . toEqual ( {
20+ headers : expect . any ( Object ) ,
21+ url : 'http://localhost:3030/' ,
22+ } ) ;
23+
24+ expect ( errorEvent . transaction ) . toEqual ( '/' ) ;
25+
26+ expect ( errorEvent . contexts ?. trace ) . toEqual ( {
27+ trace_id : expect . any ( String ) ,
28+ span_id : expect . any ( String ) ,
29+ } ) ;
30+ } ) ;
You can’t perform that action at this time.
0 commit comments