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: support ct/e2e specific overrides in cypress.json #15526

Merged
merged 19 commits into from Mar 22, 2021

Conversation

lmiller1990
Copy link
Contributor

@lmiller1990 lmiller1990 commented Mar 16, 2021

Note: Some other changes here to support create-cypress-tests wizard. Ignore those for the purpose of this review.

User facing changelog

1. Add support for runner specific overrides in cypress.json. Like this:

// cypress.json
{
    // defaults
    video: true,

    // added this e2e key
    e2e: {
	  video: false // override!
	},

    // added component
    component: { 
      viewportWidth: 500 // video is true - inherited.
    }
}

2. Pass testingType to config in plugin function

config now includes a testingType property. It is either e2e or component. The user can have conditional plugins using this flag.

module.exports = (on, config) => {
  if (config.testingType === 'component') {
    // start webpack-dev-server, etc.
  }

  if (config.testingType === 'e2e') {
    // e2e things
  }

  // You still need to return a config file.
  // e2e or CT specific config can be done in `cypress.json` using `e2e` or `component` keys.
  return config
}

Additional details

It's very useful now that we have two runners, CT and E2E.

How has the user experience changed?

You can have runner specific config, and runner specific plugins.

PR Tasks

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Mar 16, 2021

Thanks for taking the time to open a PR!

@@ -93,6 +93,10 @@ module.exports = {
}, _.cloneDeep(obj))
},

isComponentTesting (options = {}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to simplify this to a single flag at some point.

@lmiller1990 lmiller1990 marked this pull request as ready for review March 16, 2021 15:54
@github-actions
Copy link
Contributor

Internal Jira issue: TR-716

@cypress
Copy link

cypress bot commented Mar 16, 2021



Test summary

3982 0 52 1Flakiness 0


Run details

Project cypress
Status Passed
Commit c813e36
Started Mar 22, 2021 1:07 AM
Ended Mar 22, 2021 1:18 AM
Duration 10:50 💡
OS Linux Debian - 10.5
Browser Firefox 77

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

@brian-mann
Copy link
Member

Worth noting the latest working session notes are here: https://www.notion.so/cypressdx/Config-Changes-for-7-0-ce5f6221b6d64b55b5cc633460463b13

Copy link
Contributor

@chrisbreiding chrisbreiding left a comment

Choose a reason for hiding this comment

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

I think we should add mode to the config object argument instead of adding a 3rd argument. It would be consistent with what we've done with other properties that aren't strictly "config".

I also wonder if we should rethink calling it mode as well. We often refer to "run mode" and "interactive mode" depending on whether you run cypress with cypress run or cypress open, so it could be confusing to have another type of "mode" that refers to a different concept.

@JessicaSachs
Copy link
Contributor

JessicaSachs commented Mar 16, 2021

It would be consistent with what we've done with other properties that aren't strictly "config".

I also thought it was weird the @brian-mann and @flotwig wanted it as a third argument instead of on config. Were there reasons for that?

I also wonder if we should rethink calling it mode as well. We often refer to "run mode" and "interactive mode" depending on whether you run cypress with cypress run or cypress open, so it could be confusing to have another type of "mode" that refers to a different concept.

@elevatebart had the same feedback regarding naming. I'm okay with changing it.

The comments in cypress.schema.json regarding e2e vs component say Any component runner specific overrides and Any e2e runner specific overrides. That leads me to want to name it as "runnerType", "testRunnerMode".

Thoughts?

@brian-mann
Copy link
Member

My points were more broadly related to the conventions of "what exactly is configuration" - and I mentioned things like... config is really Cypress.config() which is really mutable properties that can change runtime behavior.

Whereas things like isTextTerminal, browser, testingType, etc are not config values - they are static immutable descriptors.

Yes I know we currently put things like isTextTerminal in config, but we do properly slice those out and put them as separate objects on Cypress. My point is basically to come up with a convention and agree on how to handle the different sets of values in arguments and also on the global Cypress object. It's currently inconsistent and I would rather think about the solution here to get the pattern "right" before adding more.

@brian-mann
Copy link
Member

For instance - knowing whether or not you are in open mode vs interactive mode is currently checked for by an undocumented isTextTerminal config value (which isn't really config, since its immutable) and inadequately describes the runtime environment mode.

With adding componentTesting, we now have a matrix of runtime modes.

@JessicaSachs
Copy link
Contributor

My points were more broadly related to the conventions of "what exactly is configuration" - and I mentioned things like... config is really Cypress.config() which is really mutable properties that can change runtime behavior.

Whereas things like isTextTerminal, browser, testingType, etc are not config values - they are static immutable descriptors.

Yes I know we currently put things like isTextTerminal in config, but we do properly slice those out and put them as separate objects on Cypress. My point is basically to come up with a convention and agree on how to handle the different sets of values in arguments and also on the global Cypress object. It's currently inconsistent and I would rather think about the solution here to get the pattern "right" before adding more.

Then, perhaps do we need an "immutable stuff" variable instead of just a third "mode"?

@chrisbreiding
Copy link
Contributor

My points were more broadly related to the conventions of "what exactly is configuration" - and I mentioned things like... config is really Cypress.config() which is really mutable properties that can change runtime behavior.

I generally agree and my initial implementation of providing the projectRoot and configFile to the plugins file utilized a 3rd argument for that reason. You can see the commit here. Unfortunately, I can't find the feedback/discussion that convinced me to add the properties to config instead. I think there was some dislike of calling it env and no better alternative, so we decided it was much more straightforward to simply put the properties on config.

I think we could still utilize a 3rd argument as long as it's an object. But I think that's outside the scope of this work. I advocate we add it to config for now. We can add a 3rd argument in the future that holds the extra properties, then we deprecate their usage on config.

@chrisbreiding
Copy link
Contributor

In regards to the name, just tossing out some ideas:

  • testType
  • testingType
  • specType

@brian-mann
Copy link
Member

i agree for now too.

i think maybe we could just put all of those immutable environment kinds of things on a standard key on the config object...

this is where things like browser, testingType, isTextTerminal (renamed to something better), etc could go...

Maybe config.runtime or something like that...

We would then slice out runtime from the actual config sent to Cypress.config() and would then mount those under new API's on the Cypress object.

@lmiller1990
Copy link
Contributor Author

  • For now we will move testingType to config, second arg to the plugins function.
  • Make testingType available on Cypress
  • It will not be available on Cypress.config, we will slice it out. This is similar to browser, platform, arch etc.

See the API summary here: https://www.notion.so/cypressdx/Config-Changes-for-7-0-ce5f6221b6d64b55b5cc633460463b13

const ifComponentMode = babelTypes.ifStatement(
babelTypes.binaryExpression(
'===',
babelTypes.identifier('config.mode'),
Copy link
Contributor

Choose a reason for hiding this comment

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

@lmiller1990 once you will came up with the final API – please edit this line

Suggested change
babelTypes.identifier('config.mode'),
babelTypes.identifier('config.testingType'),

And update snapshots to verify everything works as expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I can do it.

@lmiller1990
Copy link
Contributor Author

lmiller1990 commented Mar 18, 2021

I made some improvements as per this specification file.

  1. testingType is now on config when received as the second argument to the plugins function. The way is not the cleanest - I'm not sure the best place to merge it onto config. Is there a better pattern for this?
  2. testingType is available on window.Cypress.testingType. It is not available in Cypress.config('testingType'). This matches other variables like arch and browser.

packages/server/lib/plugins/child/run_plugins.js Outdated Show resolved Hide resolved
packages/server/lib/plugins/index.js Outdated Show resolved Hide resolved
packages/server/lib/util/settings.js Show resolved Hide resolved
packages/server/lib/config_options.ts Outdated Show resolved Hide resolved
packages/server/lib/util/settings.js Show resolved Hide resolved
@lmiller1990
Copy link
Contributor Author

Improved validation on nested config:

image

image

Copy link
Contributor

@chrisbreiding chrisbreiding left a comment

Choose a reason for hiding this comment

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

Great stuff! 👍

@chrisbreiding chrisbreiding merged commit 43c8ae2 into develop Mar 22, 2021
chrisbreiding added a commit that referenced this pull request Mar 22, 2021
@lmiller1990 lmiller1990 deleted the cypress-json branch March 22, 2021 03:49
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Apr 5, 2021

Released in 7.0.0.

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

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Apr 5, 2021
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.

None yet

5 participants