File tree 9 files changed +208
-482
lines changed
dev-packages/e2e-tests/test-applications/react-create-hash-router
9 files changed +208
-482
lines changed Original file line number Diff line number Diff line change 46
46
]
47
47
},
48
48
"devDependencies" : {
49
+ "@sentry-internal/event-proxy-server" : " link:../../../event-proxy-server" ,
49
50
"@playwright/test" : " 1.26.1" ,
50
51
"serve" : " 14.0.1"
51
52
},
Original file line number Diff line number Diff line change 1
- import type { PlaywrightTestConfig } from '@playwright/test' ;
2
1
import { devices } from '@playwright/test' ;
3
2
3
+ const serverPort = 3030 ;
4
+ const eventProxyPort = 3031 ;
5
+
4
6
/**
5
7
* See https://playwright.dev/docs/test-configuration.
6
8
*/
7
- const config : PlaywrightTestConfig = {
9
+ const config = {
8
10
testDir : './tests' ,
9
11
/* Maximum time one test can run for. */
10
12
timeout : 150_000 ,
@@ -32,6 +34,9 @@ const config: PlaywrightTestConfig = {
32
34
33
35
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
34
36
trace : 'on-first-retry' ,
37
+
38
+ /* Base URL to use in actions like `await page.goto('/')`. */
39
+ baseURL : `http://localhost:${ serverPort } ` ,
35
40
} ,
36
41
37
42
/* Configure projects for major browsers */
@@ -58,13 +63,19 @@ const config: PlaywrightTestConfig = {
58
63
] ,
59
64
60
65
/* 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 ,
66
70
} ,
67
- } ,
71
+ {
72
+ command : 'pnpm start' ,
73
+ port : serverPort ,
74
+ env : {
75
+ PORT : '3030' ,
76
+ } ,
77
+ } ,
78
+ ] ,
68
79
} ;
69
80
70
81
export default config ;
Original file line number Diff line number Diff line change @@ -32,34 +32,15 @@ Sentry.init({
32
32
tracesSampleRate : 1.0 ,
33
33
release : 'e2e-test' ,
34
34
35
+ tunnel : 'http://localhost:3031' ,
36
+
35
37
// Always capture replays, so we can test this properly
36
38
replaysSessionSampleRate : 1.0 ,
37
39
replaysOnErrorSampleRate : 0.0 ,
38
40
39
41
debug : true ,
40
42
} ) ;
41
43
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
-
63
44
const sentryCreateHashRouter = Sentry . wrapCreateBrowserRouter ( createHashRouter ) ;
64
45
65
46
const router = sentryCreateHashRouter ( [
Original file line number Diff line number Diff line change 1
- import * as Sentry from '@sentry/react' ;
2
1
// biome-ignore lint/nursery/noUnusedImports: Need React import for JSX
3
2
import * as React from 'react' ;
4
3
import { Link } from 'react-router-dom' ;
@@ -11,8 +10,7 @@ const Index = () => {
11
10
value = "Capture Exception"
12
11
id = "exception-button"
13
12
onClick = { ( ) => {
14
- const eventId = Sentry . captureException ( new Error ( 'I am an error!' ) ) ;
15
- window . capturedExceptionId = eventId ;
13
+ throw new Error ( 'I am an error!' ) ;
16
14
} }
17
15
/>
18
16
< 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