Skip to content
Branch: master
Find file History
bahmutov Clean up readme - remove duplicate feature lists (#299)
* move first list

* more lists

* more examples moved

* move more

* more examples

* update all blog recipes

* add two items

* move unit testing readme

* even lists moved

* more work

* more moved
Latest commit e509f00 Jun 12, 2019
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
cypress Add mocha like grep (#250) Mar 22, 2019
images Add mocha like grep (#250) Mar 22, 2019
README.md Clean up readme - remove duplicate feature lists (#299) Jun 12, 2019
cypress.json Add mocha like grep (#250) Mar 22, 2019
package.json Add mocha like grep (#250) Mar 22, 2019

README.md

Selecting tests using Mocha-like "grep"

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.

Examples

interactive

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

Running all tests with admin

headless

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

Notes

test title

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 form the given suite

$ npm run cypress:run -- --env grep='feature A'

NPM arguments

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

Quote strings with spaces

If you want to pass string with spaces, please quote it like

$ npm run cypress:run -- --env grep='feature A'

Details

See cypress/plugins/index.js file how to configure test selection preprocessor, built on top of Cypress Browserify preprocessor.

You can’t perform that action at this time.