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
Even though JavaScript is single-threaded, IO in Node.js can happen in parallel due to its async nature. AVA takes advantage of this and runs your tests concurrently, which is especially beneficial for IO heavy tests. In addition, test files are run in parallel as separate processes, giving you even better performance and an isolated environment for each test file. [Switching](https://github.com/sindresorhus/pageres/commit/663be15acb3dd2eb0f71b1956ef28c2cd3fdeed0) from Mocha to AVA in Pageres brought the test time down from 31 sec to 11 sec. Having tests run concurrently forces you to write atomic tests, meaning tests don't depend on global state or the state of other tests, which is a great thing!
8
8
@@ -128,12 +128,12 @@ $ ava --help
128
128
test.js test-*.js test/**/*.js
129
129
```
130
130
131
+
*Note that the CLI will use your local install of AVA when available, even when run globally.*
132
+
131
133
Directories are recursive by default. Directories named `fixtures` and `helpers` are ignored, as well as files starting with `_`. This can be useful for having helpers in the same directory as your test files.
132
134
133
135
When using `npm test`, you can pass positional arguments directly `npm test test2.js`, but flags needs to be passed like `npm test -- --verbose`.
134
136
135
-
*WARNING - Non-standard behavior:* The AVA CLI will always try to use your projects local install of AVA. This is true even when you run the global `ava` command. This non-standard behavior solves an important [issue](https://github.com/sindresorhus/ava/issues/157), and should have no impact on everyday use.
136
-
137
137
## Configuration
138
138
139
139
All of the CLI options can be configured in the `ava` section of your `package.json`. This allows you to modify the default behavior of the `ava` command, so you don't have to repeatedly type the same options on the command prompt.
@@ -146,9 +146,7 @@ All of the CLI options can be configured in the `ava` section of your `package.j
146
146
"!**/not-this-file.js"
147
147
],
148
148
"failFast": true,
149
-
"serial": true,
150
149
"tap": true,
151
-
"verbose": true,
152
150
"require": [
153
151
"babel-core/register"
154
152
]
@@ -200,7 +198,7 @@ test(function name(t) {
200
198
201
199
### Assertion plan
202
200
203
-
An assertion plan can be used to ensure a specific number of assertions are made. In the most common scenario, it validates that the test didn't exit before executing the expected number of assertions. It also fails the test if too many assertions are executed, which can be useful if you have assertions inside callbacks or loops.
201
+
An assertion plan can be used to ensure a specific number of assertions are made. In the most common scenario, it validates that the test didn't exit before executing the expected number of assertions. It also fails the test if too many assertions are executed, which can be useful if you have assertions inside callbacks or loops. Be aware that, unlike node-tap & tape, AVA does *not* auto-end a test when the planned assertion count is reached.
204
202
205
203
This will result in a passed test:
206
204
@@ -214,47 +212,15 @@ test(t => {
214
212
});
215
213
216
214
test.cb(t=> {
217
-
setTimeout(() => {
215
+
t.plan(1);
216
+
217
+
someAsyncFunction(() => {
218
218
t.pass();
219
219
t.end();
220
-
}, 100);
221
-
});
222
-
```
223
-
224
-
#### WARNING: Recent breaking change.
225
-
226
-
AVA no longer supports automatically ending tests via `t.plan(...)`. This helps prevent false positives if you add assertions, but forget to increase your plan count.
227
-
228
-
```js
229
-
// This no longer works
230
-
231
-
test('auto ending is dangerous', t=> {
232
-
t.plan(2);
233
-
234
-
t.pass();
235
-
t.pass();
236
-
237
-
// auto-ending after reaching the planned two assertions will miss this final one
238
-
setTimeout(() =>t.fail(), 10000);
220
+
});
239
221
});
240
222
```
241
223
242
-
For this to work, you must now use "callback mode", and explicitly call `t.end()`.
243
-
244
-
```js
245
-
test.cb('explicitly end your tests', t=> {
246
-
t.plan(2);
247
-
248
-
t.pass();
249
-
t.pass();
250
-
251
-
setTimeout(() => {
252
-
// This failure is now reliably caught.
253
-
t.fail();
254
-
t.end();
255
-
}, 1000);
256
-
});
257
-
```
258
224
259
225
### Serial-tests
260
226
@@ -737,11 +703,6 @@ AVA, not Ava or ava. Pronounced [`/ˈeɪvə/` ay-və](media/pronunciation.m4a?ra
737
703
-[Twitter](https://twitter.com/ava__js)
738
704
739
705
740
-
## Other
741
-
742
-
-[AVA logo stickers](https://www.stickermule.com/user/1070705604/stickers)
743
-
744
-
745
706
## Related
746
707
747
708
-[gulp-ava](https://github.com/sindresorhus/gulp-ava) - Run tests with gulp
@@ -750,6 +711,11 @@ AVA, not Ava or ava. Pronounced [`/ˈeɪvə/` ay-və](media/pronunciation.m4a?ra
750
711
-[start-ava](https://github.com/start-runner/ava) - Run tests with start
751
712
752
713
714
+
## Links
715
+
716
+
-[Buy AVA stickers](https://www.stickermule.com/user/1070705604/stickers)
0 commit comments