If you’ve amassed shed-loads of Cypress test specs, you may not wish to execute all of them each time you run your test project. Reasons for this may include:
- Running subsets of specs for different tests such as smoke tests
- Excluding specs you don’t want to run against certain environments
- Maintenance of individual or small groups of test specs
- Wanting to conserve memory
Cypress currently does not have any built-in support for annotating tests within your test code to tell the test runner to skip these tests. You can however use Cypress configuration options to control which directories or files Cypress will load tests from.
The config options Cypress provides for controlling the loading of test files are:
| Option | Default | Description |
|---|---|---|
| testFiles | **/*.* | A String or Array of glob patterns of the test files to load |
| ignoreTestFiles | *.hot-update.js | A String or Array of glob patterns used to ignore test files that would otherwise be shown in your list of tests. Cypress uses minimatch with the options: {dot: true, matchBase: true}. We suggest using http://globtester.com to test what files would match. |
Cypress config options can be added to cypress.json file which will be read every time Cypress is run.
If you wish to set values on a per-run basis, then config option values can be specified at the command line.
Alternatively, tests may be selected using the –spec command line parameter.
Note: The --spec command applies only to cypress run i.e. it will only work when running in ci mode.
Command-line file config option examples
Load a single spec file in CI mode
yarn cypress run --config testFiles="**/getUserDetails.spec.js"
Load all spec files from a single directory in interactive mode
yarn cypress open --config testFiles="**/websockets/*"
Load all spec files found in a directory and its subdirectories excluding those prefixed by “$” in interactive mode
yarn cypress open --config testFiles="**/websockets/**/[!$]*"
Command-line using the –spec command
Load a single defined spec file in CI mode
yarn cypress run --spec ‘**/getUserDetails.spec.js’
Load multiple defined spec files in CI mode
yarn cypress run --spec ‘**/getUserDetails.spec.js,**/getWallets.spec.js’
Load multiple spec files from a directory and its subdirectories using wildcards in CI mode
yarn cypress run --spec “**/admin-service/**/get*.spec.js”
Load all spec files from multiple directories in ci mode
yarn cypress run --spec '**/client-service/**/[!$]*,**/websockets/**/[!$]*'
Load all spec files from multiple directories excluding those in one of the directories prefixed with “$” in ci mode
yarn cypress run --spec '**/client-service/**/[!$]*,**/websockets/**/*'
Log in using your favourite account and write your comments here