@@ -13,8 +13,8 @@ import {
13
13
14
14
const SESSION_MAX_AGE = 2000 ;
15
15
16
- sentryTest ( 'handles session that exceeds max age' , async ( { getLocalTestPath, page } ) => {
17
- if ( shouldSkipReplayTest ( ) ) {
16
+ sentryTest ( 'handles session that exceeds max age' , async ( { getLocalTestPath, page, browserName } ) => {
17
+ if ( shouldSkipReplayTest ( ) || browserName === 'firefox' ) {
18
18
sentryTest . skip ( ) ;
19
19
}
20
20
@@ -82,3 +82,102 @@ sentryTest('handles session that exceeds max age', async ({ getLocalTestPath, pa
82
82
const stringifiedSnapshot2 = normalize ( fullSnapshots2 [ 0 ] ) ;
83
83
expect ( stringifiedSnapshot2 ) . toMatchSnapshot ( 'snapshot-2.json' ) ;
84
84
} ) ;
85
+
86
+ sentryTest (
87
+ 'handles many consequitive events in session that exceeds max age' ,
88
+ async ( { getLocalTestPath, page, browserName } ) => {
89
+ if ( shouldSkipReplayTest ( ) || browserName === 'firefox' ) {
90
+ sentryTest . skip ( ) ;
91
+ }
92
+
93
+ const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
94
+ const reqPromise1 = waitForReplayRequest ( page , 1 ) ;
95
+
96
+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
97
+ return route . fulfill ( {
98
+ status : 200 ,
99
+ contentType : 'application/json' ,
100
+ body : JSON . stringify ( { id : 'test-id' } ) ,
101
+ } ) ;
102
+ } ) ;
103
+
104
+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
105
+
106
+ await page . goto ( url ) ;
107
+
108
+ const replay0 = await getReplaySnapshot ( page ) ;
109
+ // We use the `initialTimestamp` of the replay to do any time based calculations
110
+ const startTimestamp = replay0 . _context . initialTimestamp ;
111
+
112
+ const req0 = await reqPromise0 ;
113
+
114
+ const replayEvent0 = getReplayEvent ( req0 ) ;
115
+ expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
116
+
117
+ const fullSnapshots0 = getFullRecordingSnapshots ( req0 ) ;
118
+ expect ( fullSnapshots0 . length ) . toEqual ( 1 ) ;
119
+ const stringifiedSnapshot = normalize ( fullSnapshots0 [ 0 ] ) ;
120
+ expect ( stringifiedSnapshot ) . toMatchSnapshot ( 'snapshot-0.json' ) ;
121
+
122
+ // Wait again for a new segment 0 (=new session)
123
+ const reqPromise2 = waitForReplayRequest ( page , 0 ) ;
124
+
125
+ // Wait for an incremental snapshot
126
+ // Wait half of the session max age (after initial flush), but account for potentially slow runners
127
+ const timePassed1 = Date . now ( ) - startTimestamp ;
128
+ await new Promise ( resolve => setTimeout ( resolve , Math . max ( SESSION_MAX_AGE / 2 - timePassed1 , 0 ) ) ) ;
129
+
130
+ await page . click ( '#button1' ) ;
131
+
132
+ const req1 = await reqPromise1 ;
133
+ const replayEvent1 = getReplayEvent ( req1 ) ;
134
+
135
+ expect ( replayEvent1 ) . toEqual ( getExpectedReplayEvent ( { segment_id : 1 , urls : [ ] } ) ) ;
136
+
137
+ const replay1 = await getReplaySnapshot ( page ) ;
138
+ const oldSessionId = replay1 . session ?. id ;
139
+
140
+ // Wait for session to expire
141
+ const timePassed2 = Date . now ( ) - startTimestamp ;
142
+ await new Promise ( resolve => setTimeout ( resolve , Math . max ( SESSION_MAX_AGE - timePassed2 , 0 ) ) ) ;
143
+
144
+ await page . evaluate ( `
145
+ Object.defineProperty(document, 'visibilityState', {
146
+ configurable: true,
147
+ get: function () {
148
+ return 'hidden';
149
+ },
150
+ });
151
+ document.dispatchEvent(new Event('visibilitychange'));
152
+ ` ) ;
153
+
154
+ // Many things going on at the same time...
155
+ void page . evaluate ( `
156
+ Object.defineProperty(document, 'visibilityState', {
157
+ configurable: true,
158
+ get: function () {
159
+ return 'visible';
160
+ },
161
+ });
162
+ document.dispatchEvent(new Event('visibilitychange'));
163
+ ` ) ;
164
+ void page . click ( '#button1' ) ;
165
+ void page . click ( '#button2' ) ;
166
+ await new Promise ( resolve => setTimeout ( resolve , 1 ) ) ;
167
+ void page . click ( '#button1' ) ;
168
+ void page . click ( '#button2' ) ;
169
+
170
+ const req2 = await reqPromise2 ;
171
+ const replay2 = await getReplaySnapshot ( page ) ;
172
+
173
+ expect ( replay2 . session ?. id ) . not . toEqual ( oldSessionId ) ;
174
+
175
+ const replayEvent2 = getReplayEvent ( req2 ) ;
176
+ expect ( replayEvent2 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
177
+
178
+ const fullSnapshots2 = getFullRecordingSnapshots ( req2 ) ;
179
+ expect ( fullSnapshots2 . length ) . toEqual ( 1 ) ;
180
+ const stringifiedSnapshot2 = normalize ( fullSnapshots2 [ 0 ] ) ;
181
+ expect ( stringifiedSnapshot2 ) . toMatchSnapshot ( 'snapshot-2.json' ) ;
182
+ } ,
183
+ ) ;
0 commit comments