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: [Multi-domain] Clean up stability code. #20656

Merged
merged 5 commits into from
Mar 18, 2022
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
2 changes: 1 addition & 1 deletion packages/driver/src/cy/multi-domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
3 changes: 1 addition & 2 deletions packages/driver/src/multi-domain/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down
14 changes: 1 addition & 13 deletions packages/driver/src/multi-domain/domain_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down
4 changes: 1 addition & 3 deletions packages/runner-shared/src/event-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
Expand Down