# Watch mode
Translations: [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/docs/recipes/watch-mode.md), [Italiano](https://github.com/avajs/ava-docs/blob/main/it_IT/docs/recipes/watch-mode.md), [Русский](https://github.com/avajs/ava-docs/blob/main/ru_RU/docs/recipes/watch-mode.md), [简体中文](https://github.com/avajs/ava-docs/blob/main/zh_CN/docs/recipes/watch-mode.md)
AVA comes with an intelligent watch mode. It watches for files to change and runs just those tests that are affected.
## Running tests with watch mode enabled
You can enable watch mode using the `--watch` or `-w` flags:
```console
$ npx ava --watch
```
Please note that integrated debugging and the TAP reporter are unavailable when using watch mode.
## Requirements
AVA uses `fs.watch()`. Support for `recursive` mode is required. Note that this has only become available on Linux since Node.js 20. [Other caveats apply](https://nodejs.org/api/fs.html#caveats), for example this won't work well on network filesystems and Docker host mounts.
## Ignoring changes
By default AVA watches for changes to all files, except for those with `.snap.md` or `.tsbuildinfo` extensions, `ava.config.*` and files in [certain directories](https://github.com/novemberborn/ignore-by-default/blob/master/index.js) as provided by the [`ignore-by-default`] package.
You can configure additional patterns for files to ignore in the [`ava` section of your `package.json`, or `ava.config.*` file][config], using the `ignoreChanges` key within the `watchMode` object:
```js
export default {
watchMode: {
ignoreChanges: ['coverage'],
},
};
```
If your tests write to disk they may trigger the watcher to rerun your tests. Configuring additional ignore patterns helps avoid this.
### Filter tests while watching
You may also filter tests while watching by using the CLI. For example, after running
```console
npx ava --watch
```
You will see a prompt like this:
```console
Type `g` followed by enter to filter test files by a glob pattern
Type `m` followed by enter to filter tests by their title
Type `r` followed by enter to rerun tests
Type `u` followed by enter to update snapshots in selected tests
>
```
So, to run only tests numbered like
- foo23434
- foo4343
- foo93823
You can type `m` and press enter, then type `foo*` and press enter. This will then run all tests that match that glob.
Afterwards you can use the `r` command to run the matched tests again, or `a` command to run **all** tests.
## Dependency tracking
AVA tracks which source files your test files depend on. If you change such a dependency only the test file that depends on it will be rerun. AVA will rerun all tests if it cannot determine which test file depends on the changed source file.
Dependency tracking works for static `import` syntax, as supported by [@vercel/nft](https://github.com/vercel/nft). `import()` is supported but dynamic paths such as `import(myVariable)` are not.
Files accessed using the `fs` module are not tracked.
## Watch mode and CI
If you run AVA in your CI with watch mode, the execution will exit with an error (`Error : Watch mode is not available in CI, as it prevents AVA from terminating.`). AVA will not run with the `--watch` (`-w`) option in CI, because CI processes should terminate, and with the `--watch` option, AVA will never terminate.
## Manually rerunning all tests
You can quickly rerun all tests by typing r on the console, followed by Enter.
## Updating snapshots
You can update failing snapshots by typing u on the console, followed by Enter.
## Debugging
Sometimes watch mode does something surprising like rerunning all tests when you thought only a single test would be run. To see its reasoning you can enable a debug mode. This will work best with the verbose reporter:
```console
$ DEBUG=ava:watcher npx ava --watch
```
[Install Troubleshooting]: https://github.com/paulmillr/chokidar#install-troubleshooting
[`ignore-by-default`]: https://github.com/novemberborn/ignore-by-default
[`.only` modifier]: ../01-writing-tests.md#running-specific-tests
[config]: ../06-configuration.md