Skip to content

Commit

Permalink
Move ignoredByWatcher to watchMode.ignoreChanges
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Jul 2, 2023
1 parent 4f52a9f commit c0b0d7b
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/06-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion docs/recipes/watch-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 5 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`));
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/globs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test-tap/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion test/globs/fixtures/ignored-by-watcher/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"type": "module",
"ava": {
"ignoredByWatcher": []
"watchMode": {
"ignoreChanges": []
}
}
}
4 changes: 2 additions & 2 deletions test/globs/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file modified test/globs/snapshots/test.js.snap
Binary file not shown.
2 changes: 1 addition & 1 deletion test/globs/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
};
Expand Down
4 changes: 3 additions & 1 deletion test/watch-mode/fixtures/basic/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
ignoredByWatcher: ['ignored-by-watcher.js'],
watchMode: {
ignoreChanges: ['ignored-by-watcher.js'],
},
};
4 changes: 3 additions & 1 deletion test/watch-mode/fixtures/exclusive/ava.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
ignoredByWatcher: ['ignored-by-watcher.js'],
watchMode: {
ignoreChanges: ['ignored-by-watcher.js'],
},
};

0 comments on commit c0b0d7b

Please sign in to comment.