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
* Allow loading of ES modules
* Automatically invoke the default export (if any) and await the result
* Pass arguments from the config to the default export (relies on "advanced" IPC for child processes)
* Document that local files are loaded through the providers (e.g. `@ava/typescript`)
Co-authored-by: Mark Wubben <[email protected]>
Copy file name to clipboardexpand all lines: docs/06-configuration.md
+80-7
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Arguments passed to the CLI will always take precedence over the CLI options con
55
55
-`verbose`: if `true`, enables verbose output (though there currently non-verbose output is not supported)
56
56
-`snapshotDir`: specifies a fixed location for storing snapshot files. Use this if your snapshots are ending up in the wrong location
57
57
-`extensions`: extensions of test files. Setting this overrides the default `["cjs", "mjs", "js"]` value, so make sure to include those extensions in the list. [Experimentally you can configure how files are loaded](#configuring-module-formats)
58
-
-`require`: extra modules to require before tests are run. Modules are required in the [worker processes](./01-writing-tests.md#test-isolation)
58
+
-`require`: [extra modules to load before test files](#requiring-extra-modules)
59
59
-`timeout`: Timeouts in AVA behave differently than in other test frameworks. AVA resets a timer after each test, forcing tests to quit if no new test results were received within the specified timeout. This can be used to handle stalled tests. See our [timeout documentation](./07-test-timeouts.md) for more options.
60
60
-`nodeArguments`: Configure Node.js arguments used to launch worker processes.
61
61
-`sortTestFiles`: A comparator function to sort test files with. Available only when using a `ava.config.*` file. See an example use case [here](recipes/splitting-tests-ci.md).
@@ -84,14 +84,14 @@ The default export can either be a plain object or a factory function which retu
84
84
85
85
```js
86
86
exportdefault {
87
-
require: ['./_my-test-helper']
87
+
require: ['./_my-test-helper.js']
88
88
};
89
89
```
90
90
91
91
```js
92
92
exportdefaultfunctionfactory() {
93
93
return {
94
-
require: ['./_my-test-helper']
94
+
require: ['./_my-test-helper.js']
95
95
};
96
96
};
97
97
```
@@ -120,14 +120,14 @@ The module export can either be a plain object or a factory function which retur
120
120
121
121
```js
122
122
module.exports= {
123
-
require: ['./_my-test-helper']
123
+
require: ['./_my-test-helper.js']
124
124
};
125
125
```
126
126
127
127
```js
128
128
module.exports= () => {
129
129
return {
130
-
require: ['./_my-test-helper']
130
+
require: ['./_my-test-helper.js']
131
131
};
132
132
};
133
133
```
@@ -154,14 +154,14 @@ The default export can either be a plain object or a factory function which retu
154
154
155
155
```js
156
156
exportdefault {
157
-
require: ['./_my-test-helper']
157
+
require: ['./_my-test-helper.js']
158
158
};
159
159
```
160
160
161
161
```js
162
162
exportdefaultfunctionfactory() {
163
163
return {
164
-
require: ['./_my-test-helper']
164
+
require: ['./_my-test-helper.js']
165
165
};
166
166
};
167
167
```
@@ -258,6 +258,79 @@ export default {
258
258
};
259
259
```
260
260
261
+
## Requiring extra modules
262
+
263
+
Use the `require` configuration to load extra modules before test files are loaded. Relative paths are resolved against the project directory and can be loaded through `@ava/typescript`. Otherwise, modules are loaded from within the `node_modules` directory inside the project.
264
+
265
+
You may specify a single value, or an array of values:
266
+
267
+
`ava.config.js`:
268
+
```js
269
+
exportdefault {
270
+
require:'./_my-test-helper.js'
271
+
}
272
+
```
273
+
```js
274
+
exportdefault {
275
+
require: ['./_my-test-helper.js']
276
+
}
277
+
```
278
+
279
+
If the module exports a function, it is called and awaited:
280
+
281
+
`_my-test-helper.js`:
282
+
```js
283
+
exportdefaultfunction () {
284
+
// Additional setup
285
+
}
286
+
```
287
+
288
+
`_my-test-helper.cjs`:
289
+
```js
290
+
module.exports=function () {
291
+
// Additional setup
292
+
}
293
+
```
294
+
295
+
In CJS files, a `default` export is also supported:
Arguments are copied using the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). This means `Map` values survive, but a `Buffer` will come out as a `Uint8Array`.
322
+
323
+
You can load dependencies installed in your project:
324
+
325
+
`ava.config.js`:
326
+
```js
327
+
exportdefault {
328
+
require:'@babel/register'
329
+
}
330
+
```
331
+
332
+
These may also export a function which is then invoked, and can receive arguments.
333
+
261
334
## Node arguments
262
335
263
336
The `nodeArguments` configuration may be used to specify additional arguments for launching worker processes. These are combined with `--node-arguments` passed on the CLI and any arguments passed to the `node` binary when starting AVA.
0 commit comments