From ebb054e5b550c4fb2c3f4929da62201b26de6cd7 Mon Sep 17 00:00:00 2001 From: Matt Henkes Date: Fri, 18 Mar 2022 12:37:29 -0500 Subject: [PATCH] chore: [Multi-domain] Clean up stability code. (#20656) * chore: [Multi-domain] Fix Flake when subdomain loads faster than toSpecBridge Command called. * Add Test * simplify test * Loading a cross domain page won't happen until the spec bridge is active (or a timeout will happen) * Update packages/driver/src/multi-domain/domain_fn.ts --- packages/driver/src/cy/multi-domain/index.ts | 2 +- packages/driver/src/multi-domain/cypress.ts | 3 +-- packages/driver/src/multi-domain/domain_fn.ts | 14 +------------- packages/runner-shared/src/event-manager.js | 4 +--- 4 files changed, 4 insertions(+), 19 deletions(-) diff --git a/packages/driver/src/cy/multi-domain/index.ts b/packages/driver/src/cy/multi-domain/index.ts index e38ad602f84a..7557eaeaf3cd 100644 --- a/packages/driver/src/cy/multi-domain/index.ts +++ b/packages/driver/src/cy/multi-domain/index.ts @@ -180,10 +180,10 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy, hookId: state('hookId'), hasVisitedAboutBlank: state('hasVisitedAboutBlank'), multiDomainBaseUrl: location.origin, + isStable: state('isStable'), }, config: preprocessConfig(Cypress.config()), env: preprocessEnv(Cypress.env()), - isStable: state('isStable'), }) } catch (err: any) { const wrappedErr = $errUtils.errByPath('switchToDomain.run_domain_fn_errored', { diff --git a/packages/driver/src/multi-domain/cypress.ts b/packages/driver/src/multi-domain/cypress.ts index 7e4b80a1772a..bf42d1d67499 100644 --- a/packages/driver/src/multi-domain/cypress.ts +++ b/packages/driver/src/multi-domain/cypress.ts @@ -100,8 +100,7 @@ const onBeforeAppWindowLoad = (Cypress: Cypress.Cypress, cy: $Cy) => (autWindow: cy.overrides.wrapNativeMethods(autWindow) const onWindowLoadPrimary = ({ url }) => { - // If the primary domain has indicated a load event, set stability to undefined, not true since the load happened in another domain. - cy.isStable(undefined, 'primary onload') + cy.isStable(true, 'primary onload') Cypress.emit('internal:window:load', { type: 'cross:domain', url }) } diff --git a/packages/driver/src/multi-domain/domain_fn.ts b/packages/driver/src/multi-domain/domain_fn.ts index 1315264ea5e2..998f42cb74d3 100644 --- a/packages/driver/src/multi-domain/domain_fn.ts +++ b/packages/driver/src/multi-domain/domain_fn.ts @@ -82,7 +82,7 @@ export const handleDomainFn = (Cypress: Cypress.Cypress, cy: $Cy) => { } Cypress.specBridgeCommunicator.on('run:domain:fn', async (options: RunDomainFnOptions) => { - const { config, data, env, fn, state, skipConfigValidation, isStable } = options + const { config, data, env, fn, state, skipConfigValidation } = options let queueFinished = false @@ -109,18 +109,6 @@ export const handleDomainFn = (Cypress: Cypress.Cypress, cy: $Cy) => { Cypress.specBridgeCommunicator.toPrimary('queue:finished', { err }, { syncGlobals: true }) }) - // We specifically don't call 'cy.isStable' here because we don't want to inject another load event. - // If stability is true in this domain, that means this domain has loaded itself, in that case trust the domain and run the next command. - if (cy.state('isStable') !== true) { - if (isStable) { - // If stability is established in a different domain, set this domain to undefined - cy.state('isStable', undefined) - } else { - // If the calling domain is unstable set this domain to also be unstable. It indicates that a load even occurred prior to running this domain. - cy.state('isStable', isStable) - } - } - try { const value = window.eval(`(${fn})`)(data) diff --git a/packages/runner-shared/src/event-manager.js b/packages/runner-shared/src/event-manager.js index 4307e0aea789..d81486a9c839 100644 --- a/packages/runner-shared/src/event-manager.js +++ b/packages/runner-shared/src/event-manager.js @@ -532,9 +532,7 @@ export const eventManager = { // Only listen to window load events from the most recent secondary domain, This prevents nondeterminism in the case where we redirect to an already // established spec bridge, but one that is not the current or next switchToDomain command. if (cy.state('latestActiveDomain') === domain) { - // Since stability was established in another domain set stable to undefined, not true. Undefined and true are treated the same stability.ts, but - // it allows us to distinguish between a load event that ocurred in this domain and some that didn't (or the initial state) - cy.isStable(undefined, 'load') + cy.isStable(true, 'load') // Prints out the newly loaded URL Cypress.emit('internal:window:load', { type: 'cross:domain', url }) }