Skip to content

Commit

Permalink
chore: Fix rerunning multidomain tests (#18090)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding authored Sep 21, 2021
1 parent cc66129 commit 416aabe
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
35 changes: 35 additions & 0 deletions packages/driver/cypress/integration/e2e/multidomain_rerun_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
describe('multidomain - rerun', () => {
beforeEach(() => {
cy.visit('/fixtures/multidomain.html')
// @ts-ignore
cy.anticipateMultidomain()
cy.get('a').click()
})

// this test will hang without the fix for multidomain rerun
// https://github.com/cypress-io/cypress/issues/18043
it('successfully reruns tests', () => {
// @ts-ignore
cy.switchToDomain('127.0.0.1:3501', () => {
cy.get('[data-cy="dom-check"]')
})
.then(() => {
const top = window.top!
const { hash } = top.location

// @ts-ignore
if (!top.hasRunOnce) {
// @ts-ignore
top.hasRunOnce = true

// hashchange causes the test to rerun
top.location.hash = `${hash}?rerun`

return
}

// this only executes after the test has been rerun
expect(true).to.be.true
})
})
})
11 changes: 0 additions & 11 deletions packages/driver/src/cy/multidomain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Bluebird from 'bluebird'
import $Log from '../../cypress/log'
import { createDeferred } from '../../util/deferred'

const readiedDomains = {}

export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, state: Cypress.State) {
Commands.addAll({
// this is a stop-gap command temporarily in use until looking ahead for
Expand All @@ -14,17 +12,8 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
state('anticipateMultidomain', true)

return new Bluebird((resolve) => {
// the spec bridge iframe only loads once, and that's when it sends
// 'cross:domain:bridge:ready', so if we've already readied it,
// there's no need to wait
if (readiedDomains[domain]) {
return resolve()
}

// @ts-ignore
Cypress.once('cross:domain:bridge:ready', () => {
readiedDomains[domain] = true

resolve()
})

Expand Down
4 changes: 4 additions & 0 deletions packages/runner-shared/src/event-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,10 @@ export const eventManager = {
ws.emit('spec:changed', specFile)
},

notifyCrossDomainBridgeReady () {
Cypress.emit('cross:domain:bridge:ready')
},

focusTests () {
ws.emit('focus:tests')
},
Expand Down
6 changes: 5 additions & 1 deletion packages/runner/src/iframe/iframes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ export default class Iframes extends Component {
const id = `Cypress (${domain})`

// if it already exists, don't add another one
if (document.getElementById(id)) return
if (document.getElementById(id)) {
this.props.eventManager.notifyCrossDomainBridgeReady()

return
}

this._addIframe({
id,
Expand Down

0 comments on commit 416aabe

Please sign in to comment.