Cypress: Support for --spec with "cypress open"

Created on 11 Jun 2018  ·  15Comments  ·  Source: cypress-io/cypress

Current behavior:

--spec flag only seems to work with the cypress run command.

Desired behavior:

Would be nice to also have this in cypress open command. In case we have several subfolders under integrations folder to distinguish types of tests, and we want to work only on one specific suite. At the moment we can't use the "Run all tests" since it will run everything.

Versions

Cypress 3.0.1

cli pkdesktop-gui proposal 💡 feature performance 🏃‍♀️

Most helpful comment

I think there should be an api that allows for cypress open with specific spec files.

Take a situation where you open cypress in the root of a monorepo:
Cypress will try grab all files for the entire monorepo which is just too much for cypress to handle.
It cant even render it's file explorer, let alone run any test, it's impossible to use this way.

Moving where Cypress is run into a subfolder is not a solution, that's a work around.
While it would work around the situation above, there are many situations where Cypress picks up files it shouldn't be touching at all.

What we want is an api where we can do cypress.open({project: projectPath, spec: specPaths})
The same as we do for run: cypress.run({project: projectPath, spec: specPaths})

All 15 comments

iirc this is a design decision from the cypress team - I was after it as well, but it looks like it will only be cypress run for at least the immediate future!

It's possible for us to implement this but it would only work for a single spec at a time, which is why we chose not to go live with it.

I see this feature useful for quickly iterating on a single spec file- possibly one that failed in CI and needs to be updated locally; however, I don't think this should be called --spec, since it will never be functionally the same as cypress run --spec because

  • cannot accept multiple spec files
  • cannot accept a pattern

How about accepting an argument that can be a file or a folder:

cypress open ~/myproject/cypress/integration/component

opens up the "cypress open" view to the ~/myproject/cypress/integration/component folder, with all the specs in the list view.

and then to specify a single spec:

cypress open ~/myproject/cypress/integration/component/component.spec.js

Which will no even spawn the spec picker window, and go straight into the spec, will live-reload, and cannot be navigated away to the "spec select" screen

The great thing about this is that it doesn't break cypress open -P ~/myproject since that functionality will continue to work.

possible issues

  • need to get cypress.json config file from somewhere, i guess we just walk up the file tree until we see a cypress.json

I think that adding a button to every folder to 'run' a folder's specs would satisfy the request in this issue, which is already outlined as part of this feature: https://github.com/cypress-io/cypress/issues/1586

I think there should be an api that allows for cypress open with specific spec files.

Take a situation where you open cypress in the root of a monorepo:
Cypress will try grab all files for the entire monorepo which is just too much for cypress to handle.
It cant even render it's file explorer, let alone run any test, it's impossible to use this way.

Moving where Cypress is run into a subfolder is not a solution, that's a work around.
While it would work around the situation above, there are many situations where Cypress picks up files it shouldn't be touching at all.

What we want is an api where we can do cypress.open({project: projectPath, spec: specPaths})
The same as we do for run: cypress.run({project: projectPath, spec: specPaths})

Take a situation where you open cypress in the root of a monorepo:
Cypress will try grab all files for the entire monorepo which is just too much for cypress to handle.
It cant even render it's file explorer, let alone run any test, it's impossible to use this way.

@Toxicable I'm curious to know more about this rendering issue of the file explorer. We are unaware of any rendering issues in the Desktop app on larger projects.

Could you provide a reproducible example? Or a gif or video of the issue?

@jennifer-shehane simply use Cypress open in the root of any large project with thousands of files, I don't think it's a Cypress bug since that would be a rediculus amount of files to render.
But it does help convey my point around having an API that allows for passing certain specs for what Cypress open should use or look for.

A specific example can be found right in this repository:

  • git clone https://github.com/cypress-io/cypress
  • cd cypress
  • echo {\"integrationFolder\": \".\", \"video\": false, \"screenshots\": false, \"suppor tFile\": false} > cypress.json
  • yarn add cypress
  • yarn cypress open

The app will open but it'll never render the filesystem.
I don't expect it to be able to, what I do expect is an API that allows us to use open with specific files Just like we can with run cypress.run({project: projectPath, spec: specPaths})
Run and Open having different apis like this is jsut feels weird, they should be as similar as possible.

We are in the same need for this option. Would be a great addition to have.

Same here! I need to filter some files out of the folder structure that gets shown with cypress open.
We have a bunch of readmes and shared code files that do not represent runnable tests that are visible within the cypress app.

Also, running all specs from a folder would also be a great addition as mentioned above.

@javiayala you can try setting the testFiles pattern in the cypress config https://docs.cypress.io/guides/references/configuration.html#Global

I want this functionality in order to implement a vscode plugin that allows you to run a spec within the file at hand. I definitely think this should be an option!

https://github.com/cypress-io/cypress/issues/3111

The option to specify the spec files for cypress open is also useful solely for splitting concerns between different stakeholders.
E.g - I want specific people to see and run different test suites (e.g Programmers will run UI tests, QAs will run and debug E2E tests, etc.).
Even without having thousands of tests like other people in this thread, just by having a bunch of tests for each stakeholder makes the usage of cypress open cumbersome.

Let's say I'm a programmer who's looking for a specific test - I'll have many tests in my view that are not mine and I'll need to sort them out. Additionally looking for me test might return additional tests that are not mine because other stakeholders also wrote their own relevant tests for that part of the application.

Right now, if I want to provide a nice and clean experience to the different local users I need to split the cypress tree structure which is pretty bothersome and requires maintenance.

I'm currently utilizing a separate config file and ignoreTestFiles to implement this. Same can be done with a config parameter though.

NPM scripts

    "cy:open:all": "cypress open",
    "cy:open:e2e": "cypress open --config ignoreTestFiles=!**/*/e2e/**/*",
    "cy:open:unit": "cypress open --config ignoreTestFiles=**/*/e2e/**/*"

I use a separate config file because I want to separate the env vars too. same thing, but move ignoreTestFiles to your config file and use -c config.e2e.json and -c config.unit.json to override the default config.json option

What's the problem with using the testFiles config option for this:

cypress open -c testFiles=src/modules/**/__tests__/*.cyp.ts works wonders for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dkreft picture dkreft  ·  3Comments

stormherz picture stormherz  ·  3Comments

brian-mann picture brian-mann  ·  3Comments

carloscheddar picture carloscheddar  ·  3Comments

jennifer-shehane picture jennifer-shehane  ·  3Comments