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

misc: Close extra tabs/windows between tests #28204

Merged
merged 10 commits into from
Nov 16, 2023

Conversation

chrisbreiding
Copy link
Contributor

@chrisbreiding chrisbreiding commented Nov 1, 2023

Additional details

Closes any extra targets (tabs/windows) between tests so that new tests always start with only the main Cypress tab, in order to maintain test isolation and a clean slate before each test. This is in anticipation of support for testing multiple tabs/windows with the future @cypress/puppeteer plugin.

Steps to test

  • Run a Cypress spec in open mode that has at least a couple tests in it
  • Open a new browser tab while the tests are running
  • You should see the tab you opened automatically close before the next test starts running

How has the user experience changed?

PR Tasks

cli/CHANGELOG.md Outdated Show resolved Hide resolved
Copy link

cypress bot commented Nov 1, 2023

Passing run #52334 ↗︎

0 110 0 0 Flakiness 0

Details:

Merge remote-tracking branch 'origin/develop' into crb/cy-puppeteer-close-extra-...
Project: cypress Commit: 4a8e42421d
Status: Passed Duration: 15:06 💡
Started: Nov 16, 2023 4:17 PM Ended: Nov 16, 2023 4:32 PM

Review all test suite changes for PR #28204 ↗︎

@chrisbreiding chrisbreiding force-pushed the crb/cy-puppeteer-filter-extra-target-traffic branch from 681023a to e9a94ff Compare November 2, 2023 13:52
Base automatically changed from crb/cy-puppeteer-filter-extra-target-traffic to develop November 2, 2023 17:55
@chrisbreiding chrisbreiding force-pushed the crb/cy-puppeteer-close-extra-targets branch from c911035 to 4bfd3c0 Compare November 3, 2023 13:51
@@ -573,6 +573,18 @@ export class BrowserCriClient {
this.extraTargetClients.delete(targetId)
}

async closeExtraTargets () {
for (const [targetId] of this.extraTargetClients) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this for loop with the awaited promise will be blocking -- would it be better to map these and use Promise.all to ensure each completes if we do need to wait on these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's intended to be blocking and will await all of them as-is. Using Promise.all would run them in parallel, but I'm not sure that's advisable with CDP. I think it's a safer bet to run them serially.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why wouldn't that be advisable with CDP? I think using Promise.all makes sense here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought there was a case where CDP had trouble with too many commands being run at once, but I can't find that instance. I updated it to run the target closing in parallel.

cli/CHANGELOG.md Outdated Show resolved Hide resolved
cli/CHANGELOG.md Outdated Show resolved Hide resolved
* Closes extra targets that are not the Cypress tab
*/
async closeExtraTargets () {
if (!instance || !instance.browser) return
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!instance || !instance.browser) return
if (!instance?.browser) return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 62e08a3

@chrisbreiding chrisbreiding merged commit 424d408 into develop Nov 16, 2023
81 of 82 checks passed
@chrisbreiding chrisbreiding deleted the crb/cy-puppeteer-close-extra-targets branch November 16, 2023 16:39
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 21, 2023

Released in 13.6.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v13.6.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Nov 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants