mirror of
https://github.com/cypress-io/cypress.git
synced 2026-04-28 19:00:03 -05:00
fix: (multi-domain) fix injection issue (#20816)
This commit is contained in:
@@ -50,7 +50,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => {
|
||||
})
|
||||
|
||||
it('window:before:unload', () => {
|
||||
cy.switchToDomain('http://foobar.com:3500', () => {
|
||||
cy.switchToDomain('http://www.foobar.com:3500', () => {
|
||||
const afterWindowBeforeUnload = new Promise<void>((resolve) => {
|
||||
Cypress.once('window:before:unload', () => {
|
||||
expect(location.host).to.equal('foobar.com:3500')
|
||||
@@ -58,15 +58,14 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => {
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: update to use relative path once available
|
||||
cy.visit('http://www.foobar.com:3500/fixtures/multi-domain.html')
|
||||
cy.visit('/fixtures/multi-domain.html')
|
||||
|
||||
cy.wrap(afterWindowBeforeUnload)
|
||||
})
|
||||
})
|
||||
|
||||
it('window:unload', () => {
|
||||
cy.switchToDomain('http://foobar.com:3500', () => {
|
||||
cy.switchToDomain('http://www.foobar.com:3500', () => {
|
||||
const afterWindowUnload = new Promise<void>((resolve) => {
|
||||
Cypress.once('window:unload', () => {
|
||||
expect(location.host).to.equal('foobar.com:3500')
|
||||
@@ -74,8 +73,7 @@ describe('multi-domain', { experimentalSessionSupport: true }, () => {
|
||||
})
|
||||
})
|
||||
|
||||
// TODO: update to use relative path once available
|
||||
cy.visit('http://www.foobar.com:3500/fixtures/multi-domain.html')
|
||||
cy.visit('/fixtures/multi-domain.html')
|
||||
|
||||
cy.wrap(afterWindowUnload)
|
||||
})
|
||||
|
||||
@@ -241,11 +241,7 @@ const MaybeDelayForMultiDomain: ResponseMiddleware = function () {
|
||||
this.debug('is cross-domain, delay until ready:for:domain event')
|
||||
|
||||
this.serverBus.once('ready:for:domain', ({ failed }) => {
|
||||
this.debug(`ready for domain${failed ? ' failed' : ''}, let it go`)
|
||||
|
||||
if (!failed) {
|
||||
this.res.wantsInjection = 'fullMultiDomain'
|
||||
}
|
||||
this.debug(`received ready:for:domain${failed ? ' failed' : ''}, let the response proceed`)
|
||||
|
||||
this.next()
|
||||
})
|
||||
|
||||
@@ -219,8 +219,6 @@ describe('http/response-middleware', function () {
|
||||
|
||||
ctx.serverBus.once.withArgs('ready:for:domain').args[0][1]({ originPolicy: 'http://idp.com' })
|
||||
|
||||
expect(ctx.res.wantsInjection).to.equal('fullMultiDomain')
|
||||
|
||||
return promise
|
||||
})
|
||||
|
||||
@@ -272,8 +270,6 @@ describe('http/response-middleware', function () {
|
||||
|
||||
ctx.serverBus.once.withArgs('ready:for:domain').args[0][1]({ originPolicy: 'http://foobar.com' })
|
||||
|
||||
expect(ctx.res.wantsInjection).to.equal('fullMultiDomain')
|
||||
|
||||
return promise
|
||||
})
|
||||
|
||||
@@ -300,8 +296,6 @@ describe('http/response-middleware', function () {
|
||||
|
||||
ctx.serverBus.once.withArgs('ready:for:domain').args[0][1]({ failed: true })
|
||||
|
||||
expect(ctx.res.wantsInjection).to.be.undefined
|
||||
|
||||
return promise
|
||||
})
|
||||
|
||||
|
||||
@@ -29,13 +29,6 @@ const findCypress = () => {
|
||||
|
||||
const Cypress = findCypress()
|
||||
|
||||
// TODO: If the spec bridge is not found we should throw some kind of error to main cypress, this should account for redirects so maybe wait a bit before throwing?
|
||||
// This may not be needed if we defer to the first command
|
||||
if (!Cypress) {
|
||||
throw new Error('Something went terribly wrong and we cannot proceed. We expected to find the global \
|
||||
Cypress in the spec bridge window but it is missing.')
|
||||
}
|
||||
|
||||
// the timers are wrapped in the injection code similar to the primary domain
|
||||
const timers = createTimers()
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ export class RemoteStates {
|
||||
get (url: string) {
|
||||
const state = this.remoteStates.get(cors.getOriginPolicy(url))
|
||||
|
||||
debug('Getting remote state: %o for: %s', state, url)
|
||||
debug('getting remote state: %o for: %s', state, url)
|
||||
|
||||
return _.cloneDeep(state)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ export class RemoteStates {
|
||||
}
|
||||
|
||||
reset () {
|
||||
debug('Resetting remote state')
|
||||
debug('resetting remote state')
|
||||
|
||||
const stateArray = Array.from(this.remoteStates.entries())
|
||||
|
||||
@@ -133,14 +133,20 @@ export class RemoteStates {
|
||||
this.originStack[0] = remoteOriginPolicy
|
||||
}
|
||||
|
||||
debug('Setting remote state %o for %s', state, remoteOriginPolicy)
|
||||
debug('setting remote state %o for %s', state, remoteOriginPolicy)
|
||||
|
||||
return this.get(remoteOriginPolicy) as Cypress.RemoteState
|
||||
}
|
||||
|
||||
addEventListeners (eventEmitter: EventEmitter) {
|
||||
eventEmitter.on('ready:for:domain', ({ originPolicy, failed }) => {
|
||||
if (failed) return
|
||||
if (failed) {
|
||||
debug('received ready:for:domain failed, don\'t add origin to remote states')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
debug(`received ready:for:domain, add origin ${originPolicy} to remote states`)
|
||||
|
||||
const existingOrigin = this.remoteStates.get(originPolicy)
|
||||
|
||||
@@ -154,6 +160,8 @@ export class RemoteStates {
|
||||
})
|
||||
|
||||
eventEmitter.on('cross:origin:finished', (originPolicy) => {
|
||||
debug(`received cross:origin:finished, remove ${originPolicy} from origin stack`)
|
||||
|
||||
this.removeCurrentOrigin(originPolicy)
|
||||
})
|
||||
}
|
||||
@@ -169,7 +177,7 @@ export class RemoteStates {
|
||||
private addOrigin (originPolicy) {
|
||||
this.originStack.push(originPolicy)
|
||||
|
||||
debug('Added origin: ', originPolicy)
|
||||
debug('added origin: ', originPolicy)
|
||||
}
|
||||
|
||||
private removeCurrentOrigin (originPolicy) {
|
||||
@@ -181,6 +189,6 @@ export class RemoteStates {
|
||||
|
||||
this.originStack.pop()
|
||||
|
||||
debug('Removed current origin: ', originPolicy)
|
||||
debug('removed current origin: ', originPolicy)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user