44
55// store these on our outer top window
66// so they are globally preserved
7- if ( window . top . hasRunOnce == null ) {
8- window . top . hasRunOnce = false
9- }
10-
11- if ( window . top . previousHash == null ) {
12- window . top . previousHash = window . top . location . hash
7+ if ( window . top . runCount == null ) {
8+ window . top . runCount = 0
139}
1410
1511const isTextTerminal = Cypress . config ( 'isTextTerminal' )
@@ -20,26 +16,19 @@ describe('rerun state bugs', () => {
2016 // but we get the hashchange coverage for free on this.
2117 it ( 'stores viewport globally and does not hang on re-runs' , ( ) => {
2218 cy . viewport ( 500 , 500 ) . then ( ( ) => {
23- if ( ! window . top . hasRunOnce ) {
19+ window . top . runCount ++
20+ if ( window . top . runCount === 1 ) {
2421 // turn off mocha events for a second
2522 Cypress . config ( 'isTextTerminal' , false )
2623
27- // 1st time around
28- window . top . hasRunOnce = true
29-
30- // cause a rerun event to occur
31- // by changing the hash
32- let { hash } = window . top . location
33-
34- window . top . location . hash = `${ hash } ?rerun`
24+ // cause a rerun event to occur by triggering a hash change
25+ window . top . dispatchEvent ( new Event ( 'hashchange' ) )
26+ } else if ( window . top . runCount === 2 ) {
27+ // Second time, do nothing, with mocha events still disabled
3528 } else {
36- if ( window . top . location . hash === window . top . previousHash ) {
37- // 3rd time around
38- // let the mocha end events fire if they're supposed to
39- Cypress . config ( 'isTextTerminal' , isTextTerminal )
40- }
41-
42- window . top . location . hash = window . top . previousHash
29+ // 3rd time around
30+ // let the mocha end events fire if they're supposed to
31+ Cypress . config ( 'isTextTerminal' , isTextTerminal )
4332 }
4433 } )
4534 } )
0 commit comments