Imagine you run all Cypress specs together using the newly resurrected "Run all specs" button.
Cypress.grepFailed() from the browser's DevTools Console and voilá - the failed tests execute, while the rest of the tests are skipped.
In the video below I show a single failed test among many successful tests. Then I run just that test by executing
Cypress.grepFailed() from the DevTools Console. This repeats the single test and it fails again. Then I fix the test and it automatically reruns, showing that is is passing. Then I reset the failed tests filter by running the
Cypress.grep() from the console, and Cypress starts running all tests again.
🎁 You can find the complete project setup used as an example in the repo bahmutov/test-todomvc-using-app-actions.
- Follow the @bahmutov/cy-grep README instructions on how to use this plugin in your project
- You can run the failed tests in a single spec or when using the "Run all tests"
- We use this grep plugin across MercariUS to run lots of end-to-end tests by feature, see my presentation .
🤔 What is
@bahmutov/cy-grepplugin? A long time ago I wrote
cypress-grepplugin that added running Cypress tests by tag or part of the title. When I left the company I moved that plugin to
cypress-io/cypress-greprepo. I personally think this plugin should be a core Cypress feature. The Cypress team then moved the repo into the
cypress-io/cypressmonorepo, a move I cannot stand. When Cypress v11 changed how the
Cypress.envobject worked, I needed to fix
Cypress.grep()method, but I did not want to touch the Cypress monorepo. Thus I cloned the code back to my
bahmutov/cy-greprepo and released my first feature: running the failed tests 🎉
What Cypress needs
Cypress superpower is its GUI - the left side of the browser window that shows the Command Log. Cypress needs to expose an API for plugins to register UI components that call the API or control its functionality. For example, the above example would be so much better if my plugin could add another button next to "Rerun tests" button!