Jest: Passing `--onlyFailures` doesn't run failed tests only

Created on 15 Jun 2018  路  13Comments  路  Source: facebook/jest

馃悰 Bug Report

Passing --onlyFailures doesn't run failed tests only.

To Reproduce

// __tests__/a.test.js
it('fails', () => {
  expect(true).toBeFalsy();
});
// __tests__/b.test.js
it('passes', () => {
  expect(true).toBeTruthy();
});
// package.json
{
  "dependencies": {
    "jest": "23.1.0"
  }
}
  1. Run "npm install"
  2. Run all tests initially with ./node_modules/jest/bin/jest.js => 1 passed, 1 failed as expected.
  3. Rerun failed tests only with ./node_modules/jest/bin/jest.js --onlyFailures. Unexpectedly, all tests are run again.

Expected behavior

A single failed test is rerun.

Link to repl or repo (highly encouraged)

https://repl.it/@sergey_simonchik/rerun-failed-tests

Run npx envinfo --preset jest

  System:
    OS: Linux 4.8 Linux Mint 18.1 (Sonya)
    CPU: x64 Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
  Binaries:
    Node: 10.4.0 - ~/.nvm/versions/node/v10.4.0/bin/node
    npm: 6.1.0 - ~/.nvm/versions/node/v10.4.0/bin/npm
  npmPackages:
    jest: 23.1.0 => 23.1.0 
Feature Request Help Wanted

Most helpful comment

I agree, I think this flag should work in a single run mode as well

All 13 comments

The flag is intended for watch mode. I do agree it should probably work, though. And if _not_, we should throw when the flag is provided outside of watch mode.

@rickhanlonii @thymikee thoughts?

Sounds reasonable to make it work in regular runs too 馃憤

+1, nice feature to add

I agree, I think this flag should work in a single run mode as well

Agree that this would be very helpful in single-run mode to fit more workflows.

Any news on that?

I was surprised when this flag didn't work :(

searching for same issue,
found this thread.
maybe at least put a log using the flag, that warns users about watch mode.

Many 3rd parties introduce verbose output which sometimes we use with Jest, making this flag work will make the output of Jest much more clear and helpful to debug. This is a big thing.

I was looking for a way to run only the failed tests and ended up here 馃槃
馃憤

This is what we end up using so far:

npx jest --runInBand --ci --testNamePattern="$(python -c "from xml.dom import minidom;import re;print('|'.join([i.parentNode.attributes['name'].value.strip() for i in minidom.parse('junit.xml').getElementsByTagName('failure')]))")"

This requires jest-junit reports to be installed and configured, and python for parsing XML.

Is it time to consider removing this flag, if it hasn't worked in at least 26 months?

@SimenB May I give this a try?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

samzhang111 picture samzhang111  路  3Comments

kentor picture kentor  路  3Comments

GrigoryPtashko picture GrigoryPtashko  路  3Comments

jardakotesovec picture jardakotesovec  路  3Comments

Secretmapper picture Secretmapper  路  3Comments