chore: [Multi-domain] Resolve flaky test (#20917)

* chore: [Multi-domain] Resolve flaky test

* remove ts ignore

* update comment

* remove dead code

* Updated comment
This commit is contained in:
Matt Henkes
2022-04-05 11:39:53 -05:00
committed by GitHub
parent 15a60c17de
commit f45be5effa
2 changed files with 36 additions and 5 deletions

View File

@@ -199,6 +199,27 @@ describe('navigation events', { experimentalSessionSupport: true }, () => {
})
})
// @ts-ignore / session support is needed for visiting about:blank between tests
describe('event timing', { experimentalSessionSupport: true }, () => {
it('does not timeout when receiving a delaying:html event after switchToDomain has started, but before the spec bridge is ready', () => {
cy.visit('/fixtures/multi-domain.html')
cy.get('a[data-cy="multi-domain-secondary-link"]').click()
cy.switchToDomain('http://foobar.com:3500', () => {
cy.log('inside switchToDomain foobar')
})
// This command is run from localhost against the cross origin aut. Updating href is one of the few allowed commands. See https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#location
cy.window().then((win) => {
win.location.href = 'http://www.idp.com:3500/fixtures/multi-domain.html'
})
cy.switchToDomain('http://idp.com:3500', () => {
cy.log('inside switchToDomain idp')
})
})
})
// @ts-ignore / session support is needed for visiting about:blank between tests
describe('delayed navigation', { experimentalSessionSupport: true, defaultCommandTimeout: 2000 }, () => {
it('localhost -> localhost', () => {

View File

@@ -30,8 +30,15 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
// to provide time for the spec bridge to be set up. normally, the queue
// will not continue until the page is stable, but this signals it to go
// ahead because we're anticipating a cross origin request
// @ts-ignore
cy.isAnticipatingCrossOriginResponseFor(request)
const location = $Location.create(request.href)
// If this event has occurred while a switchToDomain command is running with
// the same origin policy, do not set the time out and allow switchToDomain
// to handle the ready for domain event
if (cy.state('currentActiveOriginPolicy') === location.originPolicy) {
return
}
// If we haven't seen a switchToDomain and cleared the timeout within 300ms,
// go ahead and inform the server 'ready:for:domain' failed and to release the
@@ -97,10 +104,14 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
const originPolicy = location.originPolicy
// This is intentionally not reset after leaving the switchToDomain command.
cy.state('latestActiveOriginPolicy', originPolicy)
// This is set while IN the switchToDomain command.
cy.state('currentActiveOriginPolicy', originPolicy)
return new Bluebird((resolve, reject, onCancel) => {
const cleanup = () => {
cy.state('currentActiveOriginPolicy', undefined)
Cypress.backend('cross:origin:finished', location.originPolicy)
communicator.off('queue:finished', onQueueFinished)
communicator.off('sync:globals', onSyncGlobals)
@@ -196,12 +207,11 @@ export function addCommands (Commands, Cypress: Cypress.Cypress, cy: Cypress.cy,
viewportHeight: Cypress.state('viewportHeight'),
runnable: serializeRunnable(Cypress.state('runnable')),
duringUserTestExecution: Cypress.state('duringUserTestExecution'),
hookId: state('hookId'),
hasVisitedAboutBlank: state('hasVisitedAboutBlank'),
hookId: Cypress.state('hookId'),
switchToDomainBaseUrl: location.origin,
parentOriginPolicies: [cy.getRemoteLocation('originPolicy')],
isStable: state('isStable'),
autOrigin: state('autOrigin'),
isStable: Cypress.state('isStable'),
autOrigin: Cypress.state('autOrigin'),
},
config: preprocessConfig(Cypress.config()),
env: preprocessEnv(Cypress.env()),