Feature: only run dependent tests on save
See original GitHub issue🚀 Feature Proposal
Stealing this from mocha-webpack/mochapack’s killer feature in --watch mode:
Unlike mocha, mochapack analyzes your dependency graph and run only those test files that were affected by this file change.
You’ll get continuous feedback whenever you make changes as all tests that are related in any way to this change will be tested again. Isn’t that awesome?
I am proposing the same feature be added to jest under a flag like --onlyOnSave.
Motivation
Running a whole test suite is slow, but immediate feedback on a change is great. Using it.only() and describe.only() gets you closer to speedy test results, but you still need to think about what tests are affected by a change in your source code. This feature reduces all that extra thought so the only thing you need to do is write changes in source and watch the related tests just run.
Example
npx jest --onlyOnSave tests/
in your editor, save a file and watch jest only run the test cases related to said file.
Outline
the implementation would come down to a few things (apologies I dont know the internal workings of jest yet):
on file change:
- build a dependency graph for changed file (find-imports can likely help with this)
- find which dependent files are test files
- execute those test files only
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:12 (1 by maintainers)

Top Related StackOverflow Question
this may be a misunderstanding, I may have not been clear enough in my description. The feature I am describing would change which test files are ran per each file write. E.g., say you have this project structure:
If I boot up
mochapack --watch, then in my editor I savea.js, only test filea.test.jswill run, if I save fileb.js, only test fileb.test.jswill run.If you want to see it yourself, then run a simple app with mochapack. Ill do my best to create an example repo later tonight, but its just the standard behavior for
mochapack --watch.This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.