@@ -36,12 +36,105 @@ test('Sends an exception to Sentry', async ({ page }) => {
36
36
`https://sentry.io/api/0/projects/${ SENTRY_TEST_ORG_SLUG } /${ SENTRY_TEST_PROJECT } /events/${ exceptionEventId } /` ,
37
37
{ headers : { Authorization : `Bearer ${ authToken } ` } } ,
38
38
) ;
39
- clearTimeout ( timeout ) ;
40
39
expect ( response ?. status ) . toBe ( 200 ) ;
41
40
break ;
42
41
} catch ( e ) {
43
42
lastErrorResponse = e ;
44
43
await new Promise ( resolve => setTimeout ( resolve , EVENT_POLLING_RETRY_INTERVAL ) ) ;
45
44
}
46
45
}
46
+
47
+ clearTimeout ( timeout ) ;
48
+ } ) ;
49
+
50
+ test ( 'Sends a pageload transaction to Sentry' , async ( { page } ) => {
51
+ await page . goto ( '/' ) ;
52
+
53
+ const recordedTransactionsHandle = await page . waitForFunction ( ( ) => {
54
+ if ( window . recordedTransactions && window . recordedTransactions ?. length >= 1 ) {
55
+ return window . recordedTransactions ;
56
+ } else {
57
+ return undefined ;
58
+ }
59
+ } ) ;
60
+ const recordedTransactionEventIds = ( await recordedTransactionsHandle . jsonValue ( ) ) as string [ ] ;
61
+
62
+ const timeout = setTimeout ( ( ) => {
63
+ throw new Error ( 'Timeout reached while polling events.' ) ;
64
+ } , EVENT_POLLING_TIMEOUT ) ;
65
+
66
+ let hadPageLoadTransaction = false ;
67
+
68
+ await Promise . all (
69
+ recordedTransactionEventIds . map ( async ( transactionEventId , i ) => {
70
+ while ( true ) {
71
+ try {
72
+ const response = await axios . get (
73
+ `https://sentry.io/api/0/projects/${ SENTRY_TEST_ORG_SLUG } /${ SENTRY_TEST_PROJECT } /events/${ transactionEventId } /` ,
74
+ { headers : { Authorization : `Bearer ${ authToken } ` } } ,
75
+ ) ;
76
+ expect ( response ?. status ) . toBe ( 200 ) ;
77
+ if ( response . data . contexts . trace . op === 'pageload' ) {
78
+ hadPageLoadTransaction = true ;
79
+ }
80
+ break ;
81
+ } catch ( e ) {
82
+ await new Promise ( resolve => setTimeout ( resolve , EVENT_POLLING_RETRY_INTERVAL ) ) ;
83
+ }
84
+ }
85
+ } ) ,
86
+ ) ;
87
+
88
+ clearTimeout ( timeout ) ;
89
+
90
+ expect ( hadPageLoadTransaction ) . toBe ( true ) ;
91
+ } ) ;
92
+
93
+ test . only ( 'Sends a navigation transaction to Sentry' , async ( { page } ) => {
94
+ await page . goto ( '/' ) ;
95
+
96
+ // Give pageload transaction time to finish
97
+ page . waitForTimeout ( 4000 ) ;
98
+
99
+ const linkElement = page . locator ( 'id=navigation' ) ;
100
+ await linkElement . click ( ) ;
101
+
102
+ const recordedTransactionsHandle = await page . waitForFunction ( ( ) => {
103
+ if ( window . recordedTransactions && window . recordedTransactions ?. length >= 2 ) {
104
+ return window . recordedTransactions ;
105
+ } else {
106
+ return undefined ;
107
+ }
108
+ } ) ;
109
+ const recordedTransactionEventIds = ( await recordedTransactionsHandle . jsonValue ( ) ) as string [ ] ;
110
+
111
+ const timeout = setTimeout ( ( ) => {
112
+ throw new Error ( 'Timeout reached while polling events.' ) ;
113
+ } , EVENT_POLLING_TIMEOUT ) ;
114
+
115
+ let hadPageNavigationTransaction = false ;
116
+
117
+ await Promise . all (
118
+ recordedTransactionEventIds . map ( async ( transactionEventId , i ) => {
119
+ while ( true ) {
120
+ try {
121
+ const response = await axios . get (
122
+ `https://sentry.io/api/0/projects/${ SENTRY_TEST_ORG_SLUG } /${ SENTRY_TEST_PROJECT } /events/${ transactionEventId } /` ,
123
+ { headers : { Authorization : `Bearer ${ authToken } ` } } ,
124
+ ) ;
125
+ expect ( response ?. status ) . toBe ( 200 ) ;
126
+ if ( response . data . contexts . trace . op === 'pageload' ) {
127
+ hadPageNavigationTransaction = true ;
128
+ }
129
+ break ;
130
+ } catch ( e ) {
131
+ await new Promise ( resolve => setTimeout ( resolve , EVENT_POLLING_RETRY_INTERVAL ) ) ;
132
+ }
133
+ }
134
+ } ) ,
135
+ ) ;
136
+
137
+ clearTimeout ( timeout ) ;
138
+
139
+ expect ( hadPageNavigationTransaction ) . toBe ( true ) ;
47
140
} ) ;
0 commit comments