@@ -14,73 +14,75 @@ import {
1414// Session should expire after 2s - keep in sync with init.js
1515const SESSION_TIMEOUT = 2000 ;
1616
17- sentryTest ( 'handles an inactive session' , async ( { getLocalTestPath, page } ) => {
18- if ( shouldSkipReplayTest ( ) ) {
19- sentryTest . skip ( ) ;
20- }
21-
22- const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
23-
24- await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
25- return route . fulfill ( {
26- status : 200 ,
27- contentType : 'application/json' ,
28- body : JSON . stringify ( { id : 'test-id' } ) ,
17+ for ( let i = 0 ; i < 100 ; i ++ ) {
18+ sentryTest ( `handles an inactive session RUN ${ i } ` , async ( { getLocalTestPath, page } ) => {
19+ if ( shouldSkipReplayTest ( ) ) {
20+ sentryTest . skip ( ) ;
21+ }
22+
23+ const reqPromise0 = waitForReplayRequest ( page , 0 ) ;
24+
25+ await page . route ( 'https://dsn.ingest.sentry.io/**/*' , route => {
26+ return route . fulfill ( {
27+ status : 200 ,
28+ contentType : 'application/json' ,
29+ body : JSON . stringify ( { id : 'test-id' } ) ,
30+ } ) ;
2931 } ) ;
30- } ) ;
3132
32- const url = await getLocalTestPath ( { testDir : __dirname } ) ;
33+ const url = await getLocalTestPath ( { testDir : __dirname } ) ;
3334
34- await page . goto ( url ) ;
35+ await page . goto ( url ) ;
3536
36- const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
37- expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
37+ const replayEvent0 = getReplayEvent ( await reqPromise0 ) ;
38+ expect ( replayEvent0 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
3839
39- const fullSnapshots0 = getFullRecordingSnapshots ( await reqPromise0 ) ;
40- expect ( fullSnapshots0 . length ) . toEqual ( 1 ) ;
41- const stringifiedSnapshot = normalize ( fullSnapshots0 [ 0 ] ) ;
42- expect ( stringifiedSnapshot ) . toMatchSnapshot ( 'snapshot-0.json' ) ;
40+ const fullSnapshots0 = getFullRecordingSnapshots ( await reqPromise0 ) ;
41+ expect ( fullSnapshots0 . length ) . toEqual ( 1 ) ;
42+ const stringifiedSnapshot = normalize ( fullSnapshots0 [ 0 ] ) ;
43+ expect ( stringifiedSnapshot ) . toMatchSnapshot ( 'snapshot-0.json' ) ;
4344
44- await page . click ( '#button1' ) ;
45+ await page . click ( '#button1' ) ;
4546
46- // We wait for another segment 0
47- const reqPromise1 = waitForReplayRequest ( page , 0 ) ;
47+ // We wait for another segment 0
48+ const reqPromise1 = waitForReplayRequest ( page , 0 ) ;
4849
49- // Now we wait for the session timeout, nothing should be sent in the meanwhile
50- await new Promise ( resolve => setTimeout ( resolve , SESSION_TIMEOUT ) ) ;
50+ // Now we wait for the session timeout, nothing should be sent in the meanwhile
51+ await new Promise ( resolve => setTimeout ( resolve , SESSION_TIMEOUT ) ) ;
5152
52- // nothing happened because no activity/inactivity was detected
53- const replay = await getReplaySnapshot ( page ) ;
54- // @ts -ignore private api
55- expect ( replay . _isEnabled ) . toEqual ( true ) ;
56- // @ts -ignore private api
57- expect ( replay . _isPaused ) . toEqual ( false ) ;
53+ // nothing happened because no activity/inactivity was detected
54+ const replay = await getReplaySnapshot ( page ) ;
55+ // @ts -ignore private api
56+ expect ( replay . _isEnabled ) . toEqual ( true ) ;
57+ // @ts -ignore private api
58+ expect ( replay . _isPaused ) . toEqual ( false ) ;
5859
59- // Now we trigger a blur event, which should move the session to paused mode
60- await page . evaluate ( ( ) => {
61- window . dispatchEvent ( new Event ( 'blur' ) ) ;
62- } ) ;
60+ // Now we trigger a blur event, which should move the session to paused mode
61+ await page . evaluate ( ( ) => {
62+ window . dispatchEvent ( new Event ( 'blur' ) ) ;
63+ } ) ;
64+
65+ const replay2 = await getReplaySnapshot ( page ) ;
66+ // @ts -ignore private api
67+ expect ( replay2 . _isEnabled ) . toEqual ( true ) ;
68+ // @ts -ignore private api
69+ expect ( replay2 . _isPaused ) . toEqual ( true ) ;
6370
64- const replay2 = await getReplaySnapshot ( page ) ;
65- // @ts -ignore private api
66- expect ( replay2 . _isEnabled ) . toEqual ( true ) ;
67- // @ts -ignore private api
68- expect ( replay2 . _isPaused ) . toEqual ( true ) ;
69-
70- // Trigger an action, should re-start the recording
71- await page . click ( '#button2' ) ;
72-
73- const replay3 = await getReplaySnapshot ( page ) ;
74- // @ts -ignore private api
75- expect ( replay3 . _isEnabled ) . toEqual ( true ) ;
76- // @ts -ignore private api
77- expect ( replay3 . _isPaused ) . toEqual ( false ) ;
78-
79- const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
80- expect ( replayEvent1 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
81-
82- const fullSnapshots1 = getFullRecordingSnapshots ( await reqPromise0 ) ;
83- expect ( fullSnapshots1 . length ) . toEqual ( 1 ) ;
84- const stringifiedSnapshot1 = normalize ( fullSnapshots1 [ 0 ] ) ;
85- expect ( stringifiedSnapshot1 ) . toMatchSnapshot ( 'snapshot-1.json' ) ;
86- } ) ;
71+ // Trigger an action, should re-start the recording
72+ await page . click ( '#button2' ) ;
73+
74+ const replay3 = await getReplaySnapshot ( page ) ;
75+ // @ts -ignore private api
76+ expect ( replay3 . _isEnabled ) . toEqual ( true ) ;
77+ // @ts -ignore private api
78+ expect ( replay3 . _isPaused ) . toEqual ( false ) ;
79+
80+ const replayEvent1 = getReplayEvent ( await reqPromise1 ) ;
81+ expect ( replayEvent1 ) . toEqual ( getExpectedReplayEvent ( { } ) ) ;
82+
83+ const fullSnapshots1 = getFullRecordingSnapshots ( await reqPromise0 ) ;
84+ expect ( fullSnapshots1 . length ) . toEqual ( 1 ) ;
85+ const stringifiedSnapshot1 = normalize ( fullSnapshots1 [ 0 ] ) ;
86+ expect ( stringifiedSnapshot1 ) . toMatchSnapshot ( 'snapshot-1.json' ) ;
87+ } ) ;
88+ }
0 commit comments