Skip to content

misc: Close extra tabs/windows between tests - #28204

Merged
chrisbreiding merged 10 commits into
developfrom
crb/cy-puppeteer-close-extra-targets
Nov 16, 2023
Merged

misc: Close extra tabs/windows between tests#28204
chrisbreiding merged 10 commits into
developfrom
crb/cy-puppeteer-close-extra-targets

Conversation

@chrisbreiding

@chrisbreiding chrisbreiding commented Nov 1, 2023

Copy link
Copy Markdown
Contributor

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

Comment thread cli/CHANGELOG.md Outdated
@cypress

cypress Bot commented Nov 1, 2023

Copy link
Copy Markdown

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
Comment thread packages/server/lib/browsers/browser-cri-client.ts
}

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

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
Copy Markdown
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.

Comment thread packages/server/lib/browsers/firefox.ts
Comment thread cli/CHANGELOG.md Outdated
Comment thread cli/CHANGELOG.md Outdated
Comment thread packages/server/lib/socket-base.ts
Comment thread packages/server/lib/browsers/index.ts Outdated
* Closes extra targets that are not the Cypress tab
*/
async closeExtraTargets () {
if (!instance || !instance.browser) return

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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
@chrisbreiding
chrisbreiding deleted the crb/cy-puppeteer-close-extra-targets branch November 16, 2023 16:39
@cypress-bot

cypress-bot Bot commented Nov 21, 2023

Copy link
Copy Markdown
Contributor

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