@@ -40,6 +40,7 @@ for (let i = 0; i < 1; i++) {
40
40
41
41
await page . goto ( url ) ;
42
42
const req0 = await reqPromise0 ;
43
+ const startTimestamp = Date . now ( ) ;
43
44
44
45
const replayEvent0 = getReplayEvent ( req0 ) ;
45
46
expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
@@ -52,9 +53,7 @@ for (let i = 0; i < 1; i++) {
52
53
// We wait for another segment 0
53
54
const reqPromise2 = waitForReplayRequest ( page , 0 ) ;
54
55
55
- // Wait a bit, but not until session max age is reached (4000ms)
56
- // Note: We assume that we'll not reach the 4000ms with the actions we did before + 200ms here
57
- await new Promise ( resolve => setTimeout ( resolve , 200 ) ) ;
56
+ // Wait for an incremental snapshot
58
57
await page . click ( '#button1' ) ;
59
58
60
59
const req1 = await reqPromise1 ;
@@ -90,12 +89,12 @@ for (let i = 0; i < 1; i++) {
90
89
const replay = await getReplaySnapshot ( page ) ;
91
90
const oldSessionId = replay . session ?. id ;
92
91
93
- await new Promise ( resolve => setTimeout ( resolve , SESSION_MAX_AGE / 2 ) ) ;
94
-
92
+ // Wait for session to expire
93
+ await new Promise ( resolve => setTimeout ( resolve , SESSION_MAX_AGE - ( Date . now ( ) - startTimestamp ) ) ) ;
95
94
await page . click ( '#button2' ) ;
96
95
97
- const replay2 = await getReplaySnapshot ( page ) ;
98
96
const req2 = await reqPromise2 ;
97
+ const replay2 = await getReplaySnapshot ( page ) ;
99
98
100
99
expect ( replay2 . session ?. id ) . not . toEqual ( oldSessionId ) ;
101
100
0 commit comments