Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix rerunning multidomain tests #18090

Merged
merged 2 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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