jestjs / jest

Delightful JavaScript Testing.
https://jestjs.io
MIT License
44.2k stars 6.46k forks source link

Only failed tests not working in watch mode #11596

Open sam-jg opened 3 years ago

sam-jg commented 3 years ago

πŸ› Bug Report

"only failed tests" mode while in watch mode continues to run every test.

To Reproduce

// test.js
test('passes', () => {
  console.log('passing test')
  expect(true).toBeTruthy();
})

test('fails', () => {
  console.log('failing test')
  expect(true).toBeFalsy();
})
// package.json
{
  "scripts": {
    "test": "jest"
  },
  "devDependencies": {
    "jest": "^27.0.4"
  }
}
  1. npm install
  2. npm test -- --watch. Both tests run, 1 pass and 1 fail
  3. f to Press f to run only failed tests. Both tests still run, 1 pass and 1 fail.

Expected behavior

After the initial run I would expect only the failing test to run

Link to repl or repo (highly encouraged)

https://replit.com/@samjg1/watch-test

envinfo

System:
    OS: macOS 11.4
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 15.11.0 - ~/.nvm/versions/node/v15.11.0/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v15.11.0/bin/yarn
    npm: 7.6.0 - ~/.nvm/versions/node/v15.11.0/bin/npm
  npmPackages:
    jest: ^27.0.4 => 27.0.4
brainkim commented 3 years ago

Also seeing this bug.

System:
    OS: macOS 11.2.2
    CPU: (8) arm64 Apple M1
  Binaries:
    Node: 14.6.0
    npm: 7.19.1
  npmPackages:
    jest: ^27.0.4
MichalLytek commented 2 years ago

I experience the same issue in all my projects.

Looks like almost no one uses that feature, hence there's so few reports here 😞

brainkim commented 2 years ago

@MichalLytek I use it and have been stuck on 26 for a while now. It’s mildly disturbing how little attention this has gotten though.

ildella commented 2 years ago

Closed my duplicate bug, here's the test repo: https://github.com/ildella/jest-watch-failures-behavior and the config

npx: installed 1 in 0.522s

  System:
    OS: Linux 5.11 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
  Binaries:
    Node: 14.18.0 - /usr/bin/node
    Yarn: 1.22.11 - ~/n/bin/yarn
    npm: 6.14.15 - ~/n/bin/npm
  npmPackages:
    jest: 27.2.5 => 27.2.5
github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

blushingpenguin commented 1 year ago

it's still an issue

bunnymatic commented 8 months ago

I'm seeing something likely related.

I have a set of failing tests.

From the command line I run yarn test --watch and it runs the failing tests.

Test Suites: 9 failed, 9 total
Tests:       0 total
Snapshots:   0 total
Time:        8.078 s

If I press f, it says nothing to do

No failed test found.
Press `f` to quit "only failed tests" mode.

Watch Usage: Press w to show more.

if I press f again, it runs all tests

Test Suites: 9 failed, 5 passed, 14 total
Tests:       54 passed, 54 total
Snapshots:   1 passed, 1 total
Time:        8.422 s

if I press f again, it says nothing to do

No failed test found.
Run Jest without `--onlyFailures` or with `--all` to run all tests.

Watch Usage: Press w to show more.

but the previous test just showed 9 failures.

If I run all yarn test and then with watch it only runs failures

$ yarn test
...
Test Suites: 9 failed, 5 passed, 14 total
Tests:       54 passed, 54 total
Snapshots:   1 passed, 1 total
Time:        12.851 s

$ yarn test --watch
Test Suites: 9 failed, 9 total
Tests:       0 total
Snapshots:   0 total
Time:        7.473 s

and again f for failed only mode does not work.

I did notice --watch --onlyFailures on the command line does initially run only failures (but it seems yarn test --watch also does that).

Then if I actually fix a test and it runs again, then it continues to run all tests.

// after repairing a test with --watch --onlyFailures flags

Test Suites: 8 failed, 1 passed, 9 total
Tests:       6 passed, 6 total
Snapshots:   0 total
Time:        8.643 s
Ran all test suites related to changed files.

It feels like the whole --watch + only failures doesn't work anymore. It's been a while but I've used it before and I remember it working. This is a new project and we've been trying to keep up with the latest.

# Mac Intel 
$ uname -a
Darwin kinda 21.6.0 Darwin Kernel Version 21.6.0: Wed Oct  4 23:55:28 PDT 2023; root:xnu-8020.240.18.704.15~1/RELEASE_X86_64 x86_64
$ node -v 
v18.14.2
$ yarn -v  
1.22.21

Jest related packages (grep jest package.json)


# Jest related packges
    "@jest/globals": "^29.7.0",
    "@testing-library/jest-dom": "^6.2.1",
    "@types/jest": "^29.5.12",
    "babel-jest": "^29.7.0",
    "eslint-plugin-jest": "^27.6.3",
    "eslint-plugin-jest-dom": "^5.1.0",
    "jest": "^29.7.0",
    "jest-environment-jsdom": "^29.7.0",
    "jest-scss-transform": "^1.0.3",
    "ts-jest": "^29.1.2",
ildella commented 8 months ago

@bunnymatic yes that's also another issue. If a test is failing in some particular way, it won't rerun in "only-failure" mode. Classic example: an error in the test suite is thrown in before* function. That woul make the suite fail, but no rerun tests in only-failure mode.

But it's a different issue.