When running npm test -- --watch
and hitting 'o' to test only updated files, all files get tested even if only one is modified.
Repo: https://github.com/ffxsam/jest-watch-strangeness
Clone and run npm install
, then npm test -- --watch
. Open up imports/features/SomeFeature/components/Thing/Thing.js
and, for example, modify line 7. Tests for Thing.js
and Whatever.js
both get run.
The changed files only mode is "best-effort". Sometimes Jest cannot accurately predict what the dependency graph will look like. In this case, I think you might have either had a local change that triggered this (like a change to Radium or something) or that there is some other confusion.
I'm struggling with the same problem, every time all my tests are run no matter which file I change.
I've trying to figure out how Jest decides what tests to run but I couldn't find anything in the docs. @cpojer is this explained somewhere? Some sort of guidance on how to help Jest to determine which tests has to run would be very helpful.
PS: thank you for Jest, it's amazing!
I just found out thanks to this video that Jest seems to use git head to figure out which tests has to run. After committing some of my changes I now see that only some tests are run (with option "o").
@cpojer I think still would be handy to have explanation how jest attempts to solve it, so maybe we could avoid some patterns to not confuse jest.
Try this
brew uninstall watchman
brew link automake
brew install --HEAD watchman
Happy coding
I'm having the same issue. I run tests using:
jest --watch --notify
and it runs tests that are completely unrelated to to the file that has changed. This is really annoying as one suite is particularly slow, which means even if I am testing one file which has a small associated test it will run the slow suite every time. How to fix this?
have you tried to clear the watchman?
watchman watch-del-all
and try to run jest again jest --watch
I had this issue when changing high-level config files (i.e. tsconfig.json
). Jest would not be able to tell how those changes affected individual tests so it rightfully reruns all tests.
Most helpful comment
I'm having the same issue. I run tests using:
jest --watch --notify
and it runs tests that are completely unrelated to to the file that has changed. This is really annoying as one suite is particularly slow, which means even if I am testing one file which has a small associated test it will run the slow suite every time. How to fix this?