@@ -39,30 +39,35 @@ for (let i = 0; i < 100; i++) {
39
39
const url = await getLocalTestPath ( { testDir : __dirname } ) ;
40
40
41
41
await page . goto ( url ) ;
42
+ const req0 = await reqPromise0 ;
42
43
43
- const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
44
+ const replayEvent0 = getReplayEvent ( req0 ) ;
44
45
expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
45
46
46
- const fullSnapshots0 = getFullRecordingSnapshots ( await reqPromise0 ) ;
47
+ const fullSnapshots0 = getFullRecordingSnapshots ( req0 ) ;
47
48
expect ( fullSnapshots0 . length ) . toEqual ( 1 ) ;
48
49
const stringifiedSnapshot = normalize ( fullSnapshots0 [ 0 ] ) ;
49
50
expect ( stringifiedSnapshot ) . toMatchSnapshot ( 'snapshot-0.json' ) ;
50
51
51
52
// We wait for another segment 0
52
53
const reqPromise2 = waitForReplayRequest ( page , 0 ) ;
53
54
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 ) ) ;
55
58
await page . click ( '#button1' ) ;
56
59
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
+
58
65
expect ( replayEvent1 ) . toEqual (
59
66
getExpectedReplayEvent ( { replay_start_timestamp : undefined , segment_id : 1 , urls : [ ] } ) ,
60
67
) ;
61
68
62
- const fullSnapshots1 = getFullRecordingSnapshots ( await reqPromise1 ) ;
63
69
expect ( fullSnapshots1 . length ) . toEqual ( 0 ) ;
64
70
65
- const incrementalSnapshots1 = getIncrementalRecordingSnapshots ( await reqPromise1 ) ;
66
71
// The number of incremental snapshots depends on the browser
67
72
expect ( incrementalSnapshots1 . length ) . toBeGreaterThanOrEqual ( 4 ) ;
68
73
@@ -90,13 +95,14 @@ for (let i = 0; i < 100; i++) {
90
95
await page . click ( '#button2' ) ;
91
96
92
97
const replay2 = await getReplaySnapshot ( page ) ;
98
+ const req2 = await reqPromise2 ;
93
99
94
100
expect ( replay2 . session ?. id ) . not . toEqual ( oldSessionId ) ;
95
101
96
- const replayEvent2 = getReplayEvent ( await reqPromise2 ) ;
102
+ const replayEvent2 = getReplayEvent ( req2 ) ;
97
103
expect ( replayEvent2 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
98
104
99
- const fullSnapshots2 = getFullRecordingSnapshots ( await reqPromise2 ) ;
105
+ const fullSnapshots2 = getFullRecordingSnapshots ( req2 ) ;
100
106
expect ( fullSnapshots2 . length ) . toEqual ( 1 ) ;
101
107
const stringifiedSnapshot2 = normalize ( fullSnapshots2 [ 0 ] ) ;
102
108
expect ( stringifiedSnapshot2 ) . toMatchSnapshot ( 'snapshot-2.json' ) ;
0 commit comments