'Is there any way to run cypress open and only include test files containing a key word? eg. lifecycle from domains-lifecycle.spec.jsx
I have a fairly large library of test files in my project (roughly 80) and I have them named with keywords ex. "create" "Edit" and "lifecycle". I want to be able to run npx cypress open
and only include all the test files that contain "lifecycle" for example. Is there something I can add to the Cypress.json globing wise?
Solution 1:[1]
To expand on @JosePita's idea, you can set up glob patterns in scripts (package.json) and by-pass the multitude config files he was concerned about.
For example, these work on my system,
"scripts": {
"cy:open": "cypress open", // all files
"cy:user": "cypress open -c testFiles=user/**/*", // just the user folder
"cy:error": "cypress open -c testFiles=**/*error*.js", // files with keyword 'error'
There's a search bar at the top of the Cypress runner, where the tests are listed, but search is all it does.
Pressing the Run all specs button runs the full set regardless of search results.
If you want to run a subset, specify the testFiles
config option on the command line.
Solution 2:[2]
From this it seems you can open it using a config file and from this you can configure what files to load on the configuration.
It's an ugly solution because you'd need to have multiple config files for all the keywords you need (and maintain them).
Another option is to have your test files separated by folders, each with it's own cypress project inside (docs and example)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Gabriel Pita |