Watch mode for only changed files (not affected files) or ignore some files when finding affected files.
See original GitHub issueđ Feature Proposal
- Allow watch mode to be configured to only run tests for files that were actually changes (instead of âaffectedâ files), or
 - Allow specifying files to be ignored when crawling the dependency tree for affected files.
 
Motivation
The watch mode looks for all specs affected by the change. Sounds great, but whenever Iâm working on a file that is toward the root of the dependency tree (e.g. redux actions or reducers), it effectively re-runs everything.
For our mid-sized project, making a change in one reducer reruns 150 out of 206 test suites, rendering the watch functionality useless (itâll take ~30 seconds to complete); it takes longer for the watch to complete a run than to re-run all the tests (due to more workers).
While searching for a specific filename could work, it doesnât work as well when changing several files of different names or patterns. I tried this, and found myself spending an inordinate amount of time trying to specify filenames in the watch mode.
Example
Given a simple project like this one, assuming each file has a corresponding spec file:
// todos/reducer.js
export default reducer /* ... */
// lists/reducer.js
export default reducer /* ... */
// reducer.js
import todos from './todos/reducer'
import lists from './lists/reducer'
export const reducer = combineReducers({ todos, lists })
// components/todo.jsx
export class Todo extends React.Component { /* ... */ }
// app.jsx
import { createStore } from 'redux'
import { reducer} from './reducer'
import { render } from 'react-dom'
const store = createStore(reducer)
render(
  <Provider store={store} />
    {/* something that ends up using Todo component */}
  </Provider>
)
When running
jest --onlyActuallyChanged --watch or jest --ignoreFilesInDependencyTree="reducer.js" --watch
Making a change to todos/reducer.js will only trigger a rerun of todos/reducer_spec.js, instead of running tests for lists/reducer_spec.js, app_spec.jsx, and components/todo_spec.jsx.
Pitch
A very large part of the JS community use Redux, and presumably everyone is having to deal with this problem. This watch setting would not be as exhaustively correct, but would be a lot faster and probably an even better experience with more rapid feedback loops that developers seek. This goes for any developer working on modules that lie at the root of an app; watch mode just becomes not effective.
I want to emphasize that I â¤ď¸Jest and think itâs an excellent testing experience, but so far Iâve found --watch (which is commonly raved about and only demonstrated with small projects) to be very close to awesome but instead isnât quite useful in the real world.
Issue Analytics
- State:
 - Created 4 years ago
 - Reactions:3
 - Comments:7 (3 by maintainers)
 

Top Related StackOverflow Question
Right now, there are a few features in watch mode to try and address the general problem:
Jest is correctly inferring that any of the dependency files may be broken by a change in the dependency. If you want to override that default behavior, you can use the filters in watch mode.
Iâm not seeing how
ignoreFilesInDependencyTreeoronlyActuallyChangedwould work generally, youâd also ignore the reducerâs own test file. Jest doesnât make any assumptions about the way you have your tests setup. It doesnât âknowâ (and wonât force you) to have a test file for each code file with a 1-1 mapping. Thatâs what the dependency tree is used for.Because the reducer is a top-level dependency here, implementing something like âonly go X levels deepâ wonât help you.
I think the root âfixâ for your core problem is a better IDE integration. You want to be able to easily configure the existing filters in a way that makes sense for what youâre trying to test. You could do it today, but it requires going to the terminal, stopping the run, hitting a few keys⌠a âfocus just this test fileâ hotkey or something similar might solve some of your pain. Work in this area is something Iâve been thinking about.
Let me know your thoughts. Pseudo-code for your suggestions if I misunderstood them is something Iâd be interested to see.
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.