You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* When worker threads are available, support asynchronous configuration loading in the ESLint plugin helper
* Experimental implementation of next-generation configuration loading. This adds support for `.mjs` files, fixing #2346. I've removed the special handling of `ava.config.js` files, relying on Node.js to follow the package type instead. We now also support asynchronous factories.
Copy file name to clipboardExpand all lines: docs/06-configuration.md
+27-4Lines changed: 27 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -73,11 +73,13 @@ To use these files:
73
73
2. Your `package.json` must not contain an `ava` property (or, if it does, it must be an empty object)
74
74
3. You must not both have an `ava.config.js`*and* an `ava.config.cjs` file
75
75
76
-
AVA recognizes `ava.config.mjs` files but refuses to load them.
76
+
AVA 3 recognizes `ava.config.mjs` files but refuses to load them. This is changing in AVA 4, [see below](#next-generation-configuration).
77
77
78
78
### `ava.config.js`
79
79
80
-
For `ava.config.js` files you must use `export default`. You cannot use ["module scope"](https://nodejs.org/docs/latest-v12.x/api/modules.html#modules_the_module_scope). You cannot import dependencies.
80
+
In AVA 3, for `ava.config.js` files you must use `export default`. You cannot use ["module scope"](https://nodejs.org/docs/latest-v12.x/api/modules.html#modules_the_module_scope). You cannot import dependencies.
81
+
82
+
This is changing in AVA 4, [see below](#next-generation-configuration).
81
83
82
84
The default export can either be a plain object or a factory function which returns a plain object:
Note that the final configuration must not be a promise.
154
+
Note that the final configuration must not be a promise. This is changing in AVA 4, [see below](#next-generation-configuration).
153
155
154
156
## Alternative configuration files
155
157
156
158
The [CLI] lets you specify a specific configuration file, using the `--config` flag. This file must have either a `.js` or `.cjs` extension and is processed like an `ava.config.js` or `ava.config.cjs` file would be.
157
159
160
+
AVA 4 also supports `.mjs` extensions, [see below](#next-generation-configuration).
161
+
158
162
When the `--config` flag is set, the provided file will override all configuration from the `package.json` and `ava.config.js` or `ava.config.cjs` files. The configuration is not merged.
159
163
160
164
The configuration file *must* be in the same directory as the `package.json` file.
@@ -182,6 +186,25 @@ module.exports = {
182
186
183
187
You can now run your unit tests through `npx ava` and the integration tests through `npx ava --config integration-tests.config.cjs`.
184
188
189
+
## Next generation configuration
190
+
191
+
AVA 4 will add full support for ESM configuration files as well as allowing you to have asynchronous factory functions. If you're using Node.js 12 or later you can opt-in to these features in AVA 3 by enabling the `nextGenConfig` experiment. Say in an `ava.config.mjs` file:
192
+
193
+
```js
194
+
exportdefault {
195
+
nonSemVerExperiments: {
196
+
nextGenConfig:true
197
+
},
198
+
files: ['unit-tests/**/*]
199
+
};
200
+
```
201
+
202
+
This also allows you to pass an `.mjs` file using the `--config` argument.
203
+
204
+
With this experiment enabled, AVA will no longer have special treatment for `ava.config.js` files. Instead AVA follows Node.js' behavior, so if you've set [`"type": "module"`](https://nodejs.org/docs/latest/api/packages.html#packages_type) you must use ESM, and otherwise you must use CommonJS.
205
+
206
+
You mustn't have an `ava.config.mjs` file next to an `ava.config.js` or `ava.config.cjs` file.
207
+
185
208
## Object printing depth
186
209
187
210
By default, AVA prints nested objects to a depth of`3`. However, when debugging tests with deeply nested objects, it can be useful to print with more detail. This can be done by setting [`util.inspect.defaultOptions.depth`](https://nodejs.org/api/util.html#util_util_inspect_defaultoptions) to the desired depth, before the test is executed:
0 commit comments