@@ -39,30 +39,35 @@ for (let i = 0; i < 100; i++) {
3939 const url = await getLocalTestPath ( { testDir : __dirname } ) ;
4040
4141 await page . goto ( url ) ;
42+ const req0 = await reqPromise0 ;
4243
43- const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
44+ const replayEvent0 = getReplayEvent ( req0 ) ;
4445 expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
4546
46- const fullSnapshots0 = getFullRecordingSnapshots ( await reqPromise0 ) ;
47+ const fullSnapshots0 = getFullRecordingSnapshots ( req0 ) ;
4748 expect ( fullSnapshots0 . length ) . toEqual ( 1 ) ;
4849 const stringifiedSnapshot = normalize ( fullSnapshots0 [ 0 ] ) ;
4950 expect ( stringifiedSnapshot ) . toMatchSnapshot ( 'snapshot-0.json' ) ;
5051
5152 // We wait for another segment 0
5253 const reqPromise2 = waitForReplayRequest ( page , 0 ) ;
5354
54- await new Promise ( resolve => setTimeout ( resolve , SESSION_MAX_AGE / 2 ) ) ;
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 ) ) ;
5558 await page . click ( '#button1' ) ;
5659
57- const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
60+ const req1 = await reqPromise1 ;
61+ const replayEvent1 = getReplayEvent ( req1 ) ;
62+ const fullSnapshots1 = getFullRecordingSnapshots ( req1 ) ;
63+ const incrementalSnapshots1 = getIncrementalRecordingSnapshots ( req1 ) ;
64+
5865 expect ( replayEvent1 ) . toEqual (
5966 getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
6067 ) ;
6168
62- const fullSnapshots1 = getFullRecordingSnapshots ( await reqPromise1 ) ;
6369 expect ( fullSnapshots1 . length ) . toEqual ( 0 ) ;
6470
65- const incrementalSnapshots1 = getIncrementalRecordingSnapshots ( await reqPromise1 ) ;
6671 // The number of incremental snapshots depends on the browser
6772 expect ( incrementalSnapshots1 . length ) . toBeGreaterThanOrEqual ( 4 ) ;
6873
@@ -90,13 +95,14 @@ for (let i = 0; i < 100; i++) {
9095 await page . click ( '#button2' ) ;
9196
9297 const replay2 = await getReplaySnapshot ( page ) ;
98+ const req2 = await reqPromise2 ;
9399
94100 expect ( replay2 . session ?. id ) . not . toEqual ( oldSessionId ) ;
95101
96- const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
102+ const replayEvent2 = getReplayEvent ( req2 ) ;
97103 expect ( replayEvent2 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
98104
99- const fullSnapshots2 = getFullRecordingSnapshots ( await reqPromise2 ) ;
105+ const fullSnapshots2 = getFullRecordingSnapshots ( req2 ) ;
100106 expect ( fullSnapshots2 . length ) . toEqual ( 1 ) ;
101107 const stringifiedSnapshot2 = normalize ( fullSnapshots2 [ 0 ] ) ;
102108 expect ( stringifiedSnapshot2 ) . toMatchSnapshot ( 'snapshot-2.json' ) ;
0 commit comments