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

feat: gate WebKit behind experimentalWebKitSupport in prod #23711

Merged
merged 22 commits into from Sep 13, 2022

Conversation

flotwig
Copy link
Contributor

@flotwig flotwig commented Sep 7, 2022

User facing changelog

  • Experimental support for running tests in WebKit, Safari's browser engine, has been added to Cypress. Set the experimentalWebKitSupport config value to true to opt-in to this experiment.

Additional details

  • To get around the fact that config.browsers is modifiable along with the rest of the config during setupNodeEvents, these are the detection rules:
    • Always detect+display if playwright-webkit is installed.
    • If experimentalWebKitSupport is not set, disable the browser and error if it's launched in run mode. In Open mode, display it greyed out and with a warning.
  • Adds errors to known-broken commands.
  • Fixes an issue with ECONNRESET on Linux - d29b5c6
  • Fixes the issue where playwright-webkit is resolved from the sourcedir, not the projectRoot, outside of development - e8c0d9a
  • Fixes an issue where Cypress failed in WK on Windows due to missing WebAssembly: f396c41
  • Fixes an issue where initial WK load would take up to 20 seconds: 3bd8a3c

Steps to test

How has the user experience changed?

  • In cypress run...
    • ...Cy exits with an error if experimentalWebKitSupport is false and --browser webkit is passed:
      image
    • Otherwise Cy attempts to require the user's playwright-webkit and use it to run tests.
  • In cypress open...
    • ...Cy does not behave differently if experimentalWebKitSupport is enabled but playwright-webkit is not installed, and no --browser --testingType is passed. Attempting to launch with the module missing results in a require error.
    • ...Cy displays WebKit disabled if experimentalWebKitSupport is false but playwright-webkit IS installed:
      image
    • ...Cy errors on project load if experimentalWebKitSupport is false and --testingType --browser webkit is passed to try and quicklaunch into WK:
      image

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Sep 7, 2022

Thanks for taking the time to open a PR!

@@ -86,7 +86,7 @@ export const AllCypressErrors = {
},
CHROME_WEB_SECURITY_NOT_SUPPORTED: (browser: string) => {
return errTemplate`\
Your project has set the configuration option: ${fmt.highlight(`chromeWebSecurity`)} to ${fmt.highlightTertiary(`false`)}
Your project has set the configuration option: \`chromeWebSecurity\` to \`false\`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

launchpad is not rendering ANSI escape sequences like desktop-gui once did, so I changed this to a plain text representation

@flotwig flotwig mentioned this pull request Sep 7, 2022
21 tasks
@@ -27,7 +27,7 @@
}"
>
<Tooltip
v-if="!browser.isVersionSupported"
v-if="browser.warning"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This also fixes an issue where the chromeWebSecurity warning did not display.

Copy link
Contributor

Choose a reason for hiding this comment

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

Did we add a regression test for this somewhere? Not sure I see it

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'd add it in this file potentially: https://github.com/cypress-io/cypress/blob/develop/packages/launchpad/cypress/e2e/config-files-error-handling.cy.ts#L96

Just pick a system-tests project that has chromeWebSecurity: false and it should show up.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are percy snapshots for the warning icon itself, does that cover the need for a test?

getAllBrowsersWith (nameOrPath?: string) {
debug('getAllBrowsersWith %o', { nameOrPath })
if (nameOrPath) {
return utils.ensureAndGetByNameOrPath(nameOrPath, true)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code path was never used so I removed this function entirely.

@@ -258,17 +262,10 @@ const getBrowsers = async () => {
version,
path: '',
majorVersion,
info: 'Electron is the default browser that comes with Cypress. This is the default browser that runs in headless mode. Selecting this browser is useful when debugging. The version number indicates the underlying Chromium version that Electron uses.',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the subject of #21769 - info display has been broken since 10.0.0. I've just removed it in lieu of adding the info display back in.

export async function open (browser: Browser, url: string, options: BrowserLaunchOpts, automation: Automation): Promise<BrowserInstance> {
if (!options.experimentalWebKitSupport) {
throw new Error('WebKit was launched, but the experimental feature was not enabled. Please add `experimentalWebKitSupport: true` to your config file to launch WebKit.')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is reached if the user passes --testingType --browser webkit and bypasses the GUI.

@cypress
Copy link

cypress bot commented Sep 7, 2022



Test summary

59 0 11 0Flakiness 0


Run details

Project cypress
Status Passed
Commit af8d3a1
Started Sep 12, 2022 8:41 PM
Ended Sep 12, 2022 8:51 PM
Duration 10:14 💡
OS Linux Debian - 11.3
Browser Chrome 100

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@flotwig flotwig marked this pull request as ready for review September 8, 2022 17:13
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Some various nits/questions but no obvious problems, testing it now.

@@ -500,14 +500,22 @@ export class ProjectConfigManager {
}

fullConfig.browsers = fullConfig.browsers?.map((browser) => {
if (browser.family === 'chromium' || fullConfig.chromeWebSecurity) {
return browser
if (browser.family === 'webkit' && !fullConfig.experimentalWebKitSupport) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you mean by confusing now, there's about 20 places we modify the config, and it's not clear if this is the right place to do it, or one of the other 19 🤔

@@ -380,6 +380,8 @@ export class ProjectLifecycleManager {
}

private _setCurrentProject (projectRoot: string) {
process.chdir(projectRoot)
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we needed to add this specifically during this PR? Or was it just a drive-by fix or sorts, not actually required for WK?
Edit: we need it for this reason:

Fixes the issue where playwright-webkit is resolved from the sourcedir, not the projectRoot, outside of development - e8c0d9a

Will leave this note to assist other reviews who might have the same question.

packages/driver/src/cypress/script_utils.ts Show resolved Hide resolved
@@ -1,6 +1,5 @@
import _ from 'lodash'
import { SourceMapConsumer } from 'source-map'
import Promise from 'bluebird'
Copy link
Contributor

Choose a reason for hiding this comment

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

Bluebird is not not bad but it contributes to "the code base showing it's age". I hope we can just rip all of bluebird out in one fowl swoop sometime.

pun absolute intended

Copy link
Contributor Author

@flotwig flotwig Sep 9, 2022

Choose a reason for hiding this comment

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

😆 Yeah, this one in particular was needed to fix typings.

packages/errors/src/errors.ts Show resolved Hide resolved
@@ -27,7 +27,7 @@
}"
>
<Tooltip
v-if="!browser.isVersionSupported"
v-if="browser.warning"
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we add a regression test for this somewhere? Not sure I see it

packages/server/lib/browsers/utils.ts Show resolved Hide resolved
packages/server/lib/unhandled_exceptions.ts Show resolved Hide resolved
@@ -27,7 +27,7 @@
}"
>
<Tooltip
v-if="!browser.isVersionSupported"
v-if="browser.warning"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'd add it in this file potentially: https://github.com/cypress-io/cypress/blob/develop/packages/launchpad/cypress/e2e/config-files-error-handling.cy.ts#L96

Just pick a system-tests project that has chromeWebSecurity: false and it should show up.

@lmiller1990
Copy link
Contributor

lmiller1990 commented Sep 9, 2022

In run mode, I notice the stack trace is kinda ugly. I wonder if it's worth the effort to truncate the error message, or just do a console.error (probably not).

 Running:  Alert.cy.tsx                                                                   (1 of 42)
WebKit was launched, but the experimental feature was not enabled. Please add `experimentalWebKitSupport: true` to your config file to launch WebKit.
Error: WebKit was launched, but the experimental feature was not enabled. Please add `experimentalWebKitSupport: true` to your config file to launch WebKit.
    at Object.open (/home/lachlan/code/work/dev/packages/server/lib/browsers/webkit.ts:47:15)
    at Object.open (/home/lachlan/code/work/dev/packages/server/lib/browsers/index.ts:109:49)
    at OpenProject.relaunchBrowser (/home/lachlan/code/work/dev/packages/server/lib/open_project.ts:150:20)
From previous event:
    at wait (/home/lachlan/code/work/dev/packages/server/lib/modes/run.ts:387:35)
    at waitForBrowserToConnect (/home/lachlan/code/work/dev/packages/server/lib/modes/run.ts:410:12)
    at runSpec (/home/lachlan/code/work/dev/packages/server/lib/modes/run.ts:709:9)
    at runEachSpec (/home/lachlan/code/work/dev/packages/server/lib/modes/run.ts:581:29)
error Command failed with exit code 1.

Just thought I'd point this out, not obvious from the screenshots in your description.

It works great in the open mode UI - nice message appears when you don't enable the flag.

Linux error is a bit janky if you don't install the deps:

image

I wonder if we want a proper error for this (nice formatting?)

It works great, the actual browser window looks quite nice, too!

image

@lmiller1990
Copy link
Contributor

lmiller1990 commented Sep 10, 2022

No code blocker for me, curious if we need to add a test for the regression you fixed w.r.t the CDP warning that wasn't displaying?

Can do separately if we are on a timeline, might be good to make an issue to track if that's the case.

@lmiller1990 lmiller1990 self-requested a review September 10, 2022 03:29
Copy link
Contributor

@lmiller1990 lmiller1990 left a comment

Choose a reason for hiding this comment

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

Code seems fine, last nice to have would be this comment: #23711 (comment) 🙏 thoughts?

@flotwig
Copy link
Contributor Author

flotwig commented Sep 12, 2022

@lmiller1990 I fixed the error display:
image

I also noticed another bug... we aren't catching GQL errors in prod... so if you don't pass --browser --e2e to quicklaunch WK, you won't even see this error... but that's out of scope of WebKit.

I'll create tasks for the missing coverage once this merges.

@lmiller1990
Copy link
Contributor

Looks good, let's ship it.

The remaining CI fails are just Percy flake, so I think it's fine to squash merge?

@flotwig flotwig merged commit 566a1a2 into develop Sep 13, 2022
@flotwig flotwig deleted the webkit-experimental branch September 13, 2022 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show tooltips for "info" property of browsers
3 participants