diff --git a/docs/06-configuration.md b/docs/06-configuration.md index a7b3fe457..1ef433e0a 100644 --- a/docs/06-configuration.md +++ b/docs/06-configuration.md @@ -43,7 +43,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con ## Options - `files`: an array of glob patterns to select test files. Files with an underscore prefix are ignored. By default only selects files with `cjs`, `mjs` & `js` extensions, even if the pattern matches other files. Specify `extensions` to allow other file extensions -- `ignoredByWatcher`: an array of glob patterns to match files that, even if changed, are ignored by the watcher. See the [watch mode recipe for details](https://github.com/avajs/ava/blob/main/docs/recipes/watch-mode.md) +- `watchMode`: See the [watch mode recipe for details](https://github.com/avajs/ava/blob/main/docs/recipes/watch-mode.md) - `match`: not typically useful in the `package.json` configuration, but equivalent to [specifying `--match` on the CLI](./05-command-line.md#running-tests-with-matching-titles) - `cache`: defaults to `true` to cache compiled files under `node_modules/.cache/ava`. If `false`, files are cached in a temporary directory instead - `concurrency`: max number of test files running at the same time (default: CPU cores) diff --git a/docs/recipes/watch-mode.md b/docs/recipes/watch-mode.md index 09ff0f125..710ce8996 100644 --- a/docs/recipes/watch-mode.md +++ b/docs/recipes/watch-mode.md @@ -37,7 +37,17 @@ Otherwise, AVA 6 uses `fs.watch()`. Support for `recursive` mode is required. No By default AVA watches for changes to all files, except for those with a `.snap.md` extension, `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 `ignoredByWatcher` key. +With AVA 5, you can configure additional patterns for files to ignore in the [`ava` section of your `package.json`, or `ava.config.*` file][config], using the `ignoredByWatcher` key. + +With AVA 6, place these patterns 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. diff --git a/lib/cli.js b/lib/cli.js index 969463429..456b2e9e4 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -327,6 +327,10 @@ export default async function loadCli() { // eslint-disable-line complexity exit('’watch’ must not be configured, use the --watch CLI flag instead.'); } + if (Object.hasOwn(conf, 'ignoredByWatcher')) { + exit('’ignoredByWatcher’ has moved to ’watchMode.ignoreChanges’.'); + } + if (!combined.tap && Object.keys(experiments).length > 0) { console.log(chalk.magenta(` ${figures.warning} Experiments are enabled. These are unsupported and may change or be removed at any time.`)); } @@ -380,7 +384,7 @@ export default async function loadCli() { // eslint-disable-line complexity let globs; try { - globs = normalizeGlobs({files: conf.files, ignoredByWatcher: conf.ignoredByWatcher, extensions, providers}); + globs = normalizeGlobs({files: conf.files, ignoredByWatcher: conf.watchMode?.ignoreChanges, extensions, providers}); } catch (error) { exit(error.message); } diff --git a/lib/globs.js b/lib/globs.js index 70bbdebd8..c789dcc97 100644 --- a/lib/globs.js +++ b/lib/globs.js @@ -39,7 +39,7 @@ export function normalizeGlobs({extensions, files: filePatterns, ignoredByWatche } if (ignoredByWatcherPatterns !== undefined && (!Array.isArray(ignoredByWatcherPatterns) || ignoredByWatcherPatterns.length === 0)) { - throw new Error('The ’ignoredByWatcher’ configuration must be an array containing glob patterns.'); + throw new Error('The ’watchMode.ignoreChanges’ configuration must be an array containing glob patterns.'); } const extensionPattern = buildExtensionPattern(extensions); diff --git a/test-tap/api.js b/test-tap/api.js index 6cc7daf89..29e748c16 100644 --- a/test-tap/api.js +++ b/test-tap/api.js @@ -17,7 +17,7 @@ async function apiCreator(options = {}) { options.concurrency = 2; options.extensions = options.extensions || ['cjs']; options.experiments = {}; - options.globs = normalizeGlobs({files: options.files, ignoredByWatcher: options.ignoredByWatcher, extensions: options.extensions, providers: []}); + options.globs = normalizeGlobs({files: options.files, ignoredByWatcher: options.watchMode?.ignoreChanges, extensions: options.extensions, providers: []}); const instance = new Api(options); return instance; diff --git a/test/globs/fixtures/ignored-by-watcher/package.json b/test/globs/fixtures/ignored-by-watcher/package.json index eb6f557ce..4679552cc 100644 --- a/test/globs/fixtures/ignored-by-watcher/package.json +++ b/test/globs/fixtures/ignored-by-watcher/package.json @@ -1,6 +1,8 @@ { "type": "module", "ava": { - "ignoredByWatcher": [] + "watchMode": { + "ignoreChanges": [] + } } } diff --git a/test/globs/snapshots/test.js.md b/test/globs/snapshots/test.js.md index c185640ff..2dc58c3bc 100644 --- a/test/globs/snapshots/test.js.md +++ b/test/globs/snapshots/test.js.md @@ -10,11 +10,11 @@ Generated by [AVA](https://avajs.dev). 'The ’files’ configuration must be an array containing glob patterns.' -## errors if top-level ignoredByWatcher is an empty array +## errors if watchMode.ignoreChanges is an empty array > fails with message - 'The ’ignoredByWatcher’ configuration must be an array containing glob patterns.' + 'The ’watchMode.ignoreChanges’ configuration must be an array containing glob patterns.' ## files can be filtered by directory diff --git a/test/globs/snapshots/test.js.snap b/test/globs/snapshots/test.js.snap index 1064b5c1a..f21455526 100644 Binary files a/test/globs/snapshots/test.js.snap and b/test/globs/snapshots/test.js.snap differ diff --git a/test/globs/test.js b/test/globs/test.js index 795377621..dae4d621c 100644 --- a/test/globs/test.js +++ b/test/globs/test.js @@ -12,7 +12,7 @@ test('errors if top-level files is an empty array', async t => { t.snapshot(cleanOutput(result.stderr), 'fails with message'); }); -test('errors if top-level ignoredByWatcher is an empty array', async t => { +test('errors if watchMode.ignoreChanges is an empty array', async t => { const options = { cwd: cwd('ignored-by-watcher'), }; diff --git a/test/watch-mode/fixtures/basic/ava.config.js b/test/watch-mode/fixtures/basic/ava.config.js index 618a8b186..cfa22d60a 100644 --- a/test/watch-mode/fixtures/basic/ava.config.js +++ b/test/watch-mode/fixtures/basic/ava.config.js @@ -1,3 +1,5 @@ export default { - ignoredByWatcher: ['ignored-by-watcher.js'], + watchMode: { + ignoreChanges: ['ignored-by-watcher.js'], + }, }; diff --git a/test/watch-mode/fixtures/exclusive/ava.config.js b/test/watch-mode/fixtures/exclusive/ava.config.js index 618a8b186..cfa22d60a 100644 --- a/test/watch-mode/fixtures/exclusive/ava.config.js +++ b/test/watch-mode/fixtures/exclusive/ava.config.js @@ -1,3 +1,5 @@ export default { - ignoredByWatcher: ['ignored-by-watcher.js'], + watchMode: { + ignoreChanges: ['ignored-by-watcher.js'], + }, };