-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
mjhenkes
merged 23 commits into
develop
from
matth/fix/cy-origin-fails-after-30-spec-bridges
Oct 19, 2022
Merged
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 2ab9f47
fix test errors
mjhenkes 84d6ed7
fix tests, ignore change to cookie
mjhenkes aba2192
Move patch code into injection
mjhenkes 5c24166
Code cleanup
mjhenkes f21928b
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes b2870c1
Fix most failing tests
mjhenkes 957b77d
Enable patching for both spec bridges and the primary cypress instance.
mjhenkes 97d958f
clean up
mjhenkes 5b656c5
Updates from self PR review
mjhenkes 8855c48
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes 1b43524
Remove before each limiting spec bridges.
mjhenkes 950dd37
rename attach function
mjhenkes 751e3f5
whoops, better call the function with the correct parameters
mjhenkes 97a8c93
Apply suggestions from code review
mjhenkes 982f0ca
Update packages/driver/src/cross-origin/communicator.ts
mjhenkes 69c2318
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes 78aacc0
Apply suggestions from code review
mjhenkes 101d19f
Apply suggestions from code review
mjhenkes b0c1e46
updated test name
mjhenkes 6cad0c5
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes f0aa7c0
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes 49ee41f
Merge branch 'develop' into matth/fix/cy-origin-fails-after-30-spec-b…
mjhenkes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }) => { | ||
Cypress.primaryOriginCommunicator.toSpecBridge(origin, responseEvent, cy.state('duringUserTestExecution')) | ||
}) | ||
|
||
Cypress.on('request:snapshot:from:spec:bridge', ({ log, name, options, specBridge, addSnapshot }: { | ||
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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') | ||
} | ||
|
@@ -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') | ||
} | ||
|
@@ -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) | ||
|
||
|
@@ -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 }) | ||
|
@@ -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') | ||
|
@@ -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 () { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.