- Use Mocha-like syntax to select tests to run
- Implemented as a preprocessor cypress-select-tests
This example uses cypress-select-tests preprocessor plugin to filter tests, similar to how Mocha has the --grep
CLI argument. This project provides an imitation using a string (no regular expressions).
Because Cypress ignores unknown CLI parameters, you need to pass grep
argument as an environment variables, for example by using --env
CLI argument.
Open Cypress GUI but only allow running tests with @admin
in the name
$ npm run cypress:open -- --env grep=@admin
shows only "@admin" tests were executed, while the rest were skipped
Run tests with edge case
in the name in headless mode
$ npm run cypress:run -- --env grep='edge case'
produces
Running: feature-a.js... (1 of 2)
picking tests to run in file cypress/integration/feature-a.js
feature A
- works
- reports for @admin
0 passing (30ms)
2 pending
Running: feature-b.js... (2 of 2)
picking tests to run in file cypress/integration/feature-b.js
feature B
- works
✓ an edge case (54ms)
- works for @admin
1 passing (87ms)
2 pending
The full test title used for string matching is a concatenation of suite names plus the test's own name.
describe('app', () => {
context('feature A', () => {
it('works', () => {
// full test name is 'app feature A works'
})
})
})
Thus you can run all tests from the given suite
$ npm run cypress:run -- --env grep='feature A'
Note how you need to use --
to separate NPM open or run script command from arguments to Cypress itself.
# runs only tests with "works" in their name
$ npm run cypress:run -- --env grep=works
If you want to pass string with spaces, please quote it like
$ npm run cypress:run -- --env grep='feature A'
See cypress/plugins/index.js file how to configure test selection preprocessor, built on top of Cypress Browserify preprocessor.