Jest: Re-run only failing tests

Created on 23 May 2017  路  12Comments  路  Source: facebook/jest


Do you want to request a feature or report a bug?

feature

What is the current behavior?

jest --watch will let you type a few keys to help you re-run tests.

What is the expected behavior?

It would be nice if I could type f or something to just re-run the tests that are currently failing.

For a large test suite, this would help to rapidly iterate on fixing specific problems.

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

$ jest --version && yarn --version && node --version v20.0.3 0.24.6 v6.10.3

Mac OS 10.12.5

pytest has a similar feature.

Feature Request Help Wanted

Most helpful comment

@brandon-pereira:

All 12 comments

Here is a use case to explain how this could be useful:

  • Let's say you are contributing to a new project for the first time
  • You start by running the entire test suite to make sure you set it up right
  • Because you are the first person to try it on Windows, there are 5 failures out of 800 tests
  • Instead of re-run the whole suite, you want to keep re-running just the failures. To fix the tests, you may or may not edit files that are relevant so the o mode might not be as helpful.

RSpec has a similar feature too, called --only-failures.

PR is most welcome! 馃榾

@kumar303
Can you take a look at #4886?

This will be in Jest 22.

Thank you @lsentkiewicz !

Was this feature added in 22? Can't find any documentation

@brandon-pereira:

Ah thanks, I was thinking more for running tests without the watch flag. Settled on using https://github.com/bZichett/jest-retry

Run only failed test feature works perfectly for TDD.
But once I fixed all the tests this mode became useless. It just says that there is nothing to run.
Would be great if there will be an option (or even default behavior) that when there are no failing tests, it will run all the tests again.

This way I can focus only on my editor and do TDD:

  • Break things (jest will focus on the failing tests)
  • Add some code to fix things (jest will rerun failing tests, or run the whole suite if it's clear)
  • Repeat.

Agreed it would make sense to automatically quit the mode after a test run without failures, provided there is a clear and obvious message informing the user that this was done. Happy to take a PR for this :)

This worked for me:
"test": "cross-env DB_ENV=testing jest --watch -f --runInBand api/libraries/libraries.test.js"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kirlat picture kirlat  路  81Comments

seibelj picture seibelj  路  116Comments

benmonro picture benmonro  路  119Comments

TYRONEMICHAEL picture TYRONEMICHAEL  路  80Comments

sterpe picture sterpe  路  70Comments