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

fix: Use post message instead of web sockets for spec bridges. #24243

Merged
merged 23 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6bf8ac1
fix: spec bridges no-longer create their own spec bridge but instead …
mjhenkes Oct 12, 2022
2ab9f47
fix test errors
mjhenkes Oct 13, 2022
84d6ed7
fix tests, ignore change to cookie
mjhenkes Oct 13, 2022
aba2192
Move patch code into injection
mjhenkes Oct 14, 2022
5c24166
Code cleanup
mjhenkes Oct 14, 2022
f21928b
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 14, 2022
b2870c1
Fix most failing tests
mjhenkes Oct 17, 2022
957b77d
Enable patching for both spec bridges and the primary cypress instance.
mjhenkes Oct 17, 2022
97d958f
clean up
mjhenkes Oct 17, 2022
5b656c5
Updates from self PR review
mjhenkes Oct 17, 2022
8855c48
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 17, 2022
1b43524
Remove before each limiting spec bridges.
mjhenkes Oct 17, 2022
950dd37
rename attach function
mjhenkes Oct 18, 2022
751e3f5
whoops, better call the function with the correct parameters
mjhenkes Oct 18, 2022
97a8c93
Apply suggestions from code review
mjhenkes Oct 18, 2022
982f0ca
Update packages/driver/src/cross-origin/communicator.ts
mjhenkes Oct 18, 2022
69c2318
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 18, 2022
78aacc0
Apply suggestions from code review
mjhenkes Oct 18, 2022
101d19f
Apply suggestions from code review
mjhenkes Oct 18, 2022
b0c1e46
updated test name
mjhenkes Oct 18, 2022
6cad0c5
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 18, 2022
f0aa7c0
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 18, 2022
49ee41f
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes Oct 19, 2022
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
44 changes: 34 additions & 10 deletions packages/app/src/runner/event-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ export class EventManager {
})

// Reflect back to the requesting origin the status of the 'duringUserTestExecution' state
Cypress.primaryOriginCommunicator.on('sync:during:user:test:execution', ({ specBridgeResponseEvent }, origin) => {
Cypress.primaryOriginCommunicator.toSpecBridge(origin, specBridgeResponseEvent, cy.state('duringUserTestExecution'))
Cypress.primaryOriginCommunicator.on('sync:during:user:test:execution', (_data, { origin, responseEvent }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

response event has moved to be part the second parameter object and no longer part of data which should be only information sent by the caller.

Cypress.primaryOriginCommunicator.toSpecBridge(origin, responseEvent, cy.state('duringUserTestExecution'))
})

Cypress.on('request:snapshot:from:spec:bridge', ({ log, name, options, specBridge, addSnapshot }: {
Expand All @@ -625,9 +625,13 @@ export class EventManager {
const eventID = log.get('id')

const requestSnapshot = () => {
return Cypress.primaryOriginCommunicator.toSpecBridgePromise(specBridge, 'snapshot:generate:for:log', {
name,
id: eventID,
return Cypress.primaryOriginCommunicator.toSpecBridgePromise({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toSpecBridgePromise now takes an object, so i can name parameters.

origin: specBridge,
event: 'snapshot:generate:for:log',
data: {
name,
id: eventID,
},
}).then((crossOriginSnapshot) => {
const snapshot = crossOriginSnapshot.body ? crossOriginSnapshot : null

Expand Down Expand Up @@ -657,7 +661,7 @@ export class EventManager {
this.localBus.emit('expect:origin', origin)
})

Cypress.primaryOriginCommunicator.on('viewport:changed', (viewport, origin) => {
Cypress.primaryOriginCommunicator.on('viewport:changed', (viewport, { origin }) => {
const callback = () => {
Cypress.primaryOriginCommunicator.toSpecBridge(origin, 'viewport:changed:end')
}
Expand All @@ -666,7 +670,7 @@ export class EventManager {
this.localBus.emit('viewport:changed', viewport, callback)
})

Cypress.primaryOriginCommunicator.on('before:screenshot', (config, origin) => {
Cypress.primaryOriginCommunicator.on('before:screenshot', (config, { origin }) => {
const callback = () => {
Cypress.primaryOriginCommunicator.toSpecBridge(origin, 'before:screenshot:end')
}
Expand Down Expand Up @@ -700,7 +704,7 @@ export class EventManager {

// This message comes from the AUT, not the spec bridge.
// This is called in the event that cookies are set in a cross origin AUT prior to attaching a spec bridge.
Cypress.primaryOriginCommunicator.on('aut:set:cookie', ({ cookie, href }, _origin, source) => {
Cypress.primaryOriginCommunicator.on('aut:set:cookie', ({ cookie, href }, { source }) => {
const { superDomain } = Cypress.Location.create(href)
const automationCookie = Cypress.Cookies.toughCookieToAutomationCookie(Cypress.Cookies.parse(cookie), superDomain)

Expand All @@ -716,7 +720,7 @@ export class EventManager {

// This message comes from the AUT, not the spec bridge.
// This is called in the event that cookies are retrieved in a cross origin AUT prior to attaching a spec bridge.
Cypress.primaryOriginCommunicator.on('aut:get:cookie', async ({ href }, _origin, source) => {
Cypress.primaryOriginCommunicator.on('aut:get:cookie', async ({ href }, { source }) => {
const { superDomain } = Cypress.Location.create(href)

const cookies = await Cypress.automation('get:cookies', { superDomain })
Expand All @@ -725,6 +729,26 @@ export class EventManager {
source?.postMessage({ event: 'cross:origin:aut:get:cookie', cookies }, '*')
})

/**
* Call a backend request for the requesting spec bridge since we cannot have websockets in the spec bridges.
* Return it's response.
*/
Cypress.primaryOriginCommunicator.on('backend:request', async ({ args }, { source, responseEvent }) => {
const response = await Cypress.backend(...args)

Cypress.primaryOriginCommunicator.toSource(source, responseEvent, response)
})

/**
* Call an automation request for the requesting spec bridge since we cannot have websockets in the spec bridges.
* Return it's response.
*/
Cypress.primaryOriginCommunicator.on('automation:request', async ({ args }, { source, responseEvent }) => {
const response = await Cypress.automation(...args)

Cypress.primaryOriginCommunicator.toSource(source, responseEvent, response)
})

// The window.top should not change between test reloads, and we only need to bind the message event when Cypress is recreated
// Forward all message events to the current instance of the multi-origin communicator
if (!window.top) throw new Error('missing window.top in event-manager')
Expand Down Expand Up @@ -863,7 +887,7 @@ export class EventManager {

notifyCrossOriginBridgeReady (origin) {
// Any multi-origin event appends the origin as the third parameter and we do the same here for this short circuit
Cypress.primaryOriginCommunicator.emit('bridge:ready', undefined, origin)
Cypress.primaryOriginCommunicator.emit('bridge:ready', undefined, { origin })
}

snapshotUnpinned () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,8 @@ context('cy.origin navigation', { browser: '!webkit' }, () => {
})
})

it('.go()', () => {
// TODO: Investigate this flaky test.
it('.go()', { retries: 15 }, () => {
cy.visit('/fixtures/primary-origin.html')
cy.get('a[data-cy="cross-origin-secondary-link"]').click()

Expand Down
11 changes: 11 additions & 0 deletions packages/driver/cypress/e2e/e2e/origin/origin.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
describe('cy.origin', { browser: '!webkit' }, () => {
it('successfully visits after creating 30 spec bridges', () => {
// Make ~30 spec bridges
for (let index = 0; index < 30; index++) {
cy.origin(`http://www.${index}.com:3500`, () => undefined)
}

cy.origin('http://www.app.foobar.com:3500', () => {
cy.visit('/fixtures/primary-origin.html')
})
})

it('passes viewportWidth/Height state to the secondary origin', () => {
const expectedViewport = [320, 480]

Expand Down
Loading