Skip to content

Commit a5e0ace

Browse files
committed
chore: fix rerunning multidomain tests
1 parent 92932c5 commit a5e0ace

File tree

4 files changed

+44
-12
lines changed

4 files changed

+44
-12
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
describe('multidomain - rerun', () => {
2+
beforeEach(() => {
3+
cy.visit('/fixtures/multidomain.html')
4+
// @ts-ignore
5+
cy.anticipateMultidomain()
6+
cy.get('a').click()
7+
})
8+
9+
// this test will hang without the fix for multidomain rerun
10+
// https://github.com/cypress-io/cypress/issues/18043
11+
it('successfully reruns tests', () => {
12+
// @ts-ignore
13+
cy.switchToDomain('127.0.0.1:3501', () => {
14+
cy.get('[data-cy="dom-check"]')
15+
})
16+
.then(() => {
17+
const top = window.top!
18+
const { hash } = top.location
19+
20+
// @ts-ignore
21+
if (!top.hasRunOnce) {
22+
// @ts-ignore
23+
top.hasRunOnce = true
24+
25+
// hashchange causes the test to rerun
26+
top.location.hash = `${hash}?rerun`
27+
28+
return
29+
}
30+
31+
// this only executes after the test has been rerun
32+
expect(true).to.be.true
33+
})
34+
})
35+
})

packages/driver/src/cy/multidomain/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Bluebird from 'bluebird'
22
import $Log from '../../cypress/log'
33
import { createDeferred } from '../../util/deferred'
44

5-
const readiedDomains = {}
6-
75
export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: Cypress.State) {
86
Commands.addAll({
97
// this is a stop-gap command temporarily in use until looking ahead for
@@ -14,17 +12,8 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
1412
state('anticipateMultidomain', true)
1513

1614
return new Bluebird((resolve) => {
17-
// the spec bridge iframe only loads once, and that's when it sends
18-
// 'cross:domain:bridge:ready', so if we've already readied it,
19-
// there's no need to wait
20-
if (readiedDomains[domain]) {
21-
return resolve()
22-
}
23-
2415
// @ts-ignore
2516
Cypress.once('cross:domain:bridge:ready', () => {
26-
readiedDomains[domain] = true
27-
2817
resolve()
2918
})
3019

packages/runner-shared/src/event-manager.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,10 @@ export const eventManager = {
623623
ws.emit('spec:changed', specFile)
624624
},
625625

626+
notifyCrossDomainBridgeReady () {
627+
Cypress.emit('cross:domain:bridge:ready')
628+
},
629+
626630
focusTests () {
627631
ws.emit('focus:tests')
628632
},

packages/runner/src/iframe/iframes.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,11 @@ export default class Iframes extends Component {
172172
const id = `Cypress (${domain})`
173173

174174
// if it already exists, don't add another one
175-
if (document.getElementById(id)) return
175+
if (document.getElementById(id)) {
176+
this.props.eventManager.notifyCrossDomainBridgeReady()
177+
178+
return
179+
}
176180

177181
this._addIframe({
178182
id,

0 commit comments

Comments
 (0)