question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Watch mode for only changed files (not affected files) or ignore some files when finding affected files.

See original GitHub issue

🚀 Feature Proposal

  1. Allow watch mode to be configured to only run tests for files that were actually changes (instead of “affected” files), or
  2. 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
scotthovestadtcommented, Apr 7, 2019

Right now, there are a few features in watch mode to try and address the general problem:

  • Jest automatically runs failing tests first on subsequent runs.
  • You can run only failing tests or filter by test name / filename regex pattern.
  • You can cancel a run and setup these filters while in watch mode.

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 ignoreFilesInDependencyTree or onlyActuallyChanged would 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.

0reactions
github-actions[bot]commented, May 2, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webpack --watch isn't compiling changed files - Stack Overflow
To fix, I re-cloned my repo and this time, created new folders and files through the command line instead of Code.
Read more >
Review changes | PyCharm Documentation - JetBrains
Display all changed files in the current change set and navigate to them. This action is only available when you review changes to...
Read more >
How to Configure Git to Ignore File Mode Changes - W3docs
Sometimes, working on local development there is a need to change permissions on various files. The tutorial will show how to ignore the...
Read more >
Jest CLI Options
Run tests related to changed files based on hg/git (uncommitted files): ... Watch mode also enables to specify the name or path to...
Read more >
Git Tutorial #11 - How to Ignore files/changes in Git? - YouTube
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found