Skip to content

Commit 187b8b4

Browse files
Juansindresorhus
Juan
authored andcommitted
Document common pitfalls (#919)
1 parent 4d3ed27 commit 187b8b4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

docs/common-pitfalls.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Common Pitfalls
2+
3+
## AVA in Docker
4+
5+
If you run AVA in Docker as part of your CI, you need to fix the appropriate environment variables. Specifically, adding `-e CI=true` in the `docker exec` command. See [https://github.com/avajs/ava/issues/751](#751).
6+
7+
AVA uses [is-ci](https://github.com/watson/is-ci) to decide if it's in a CI environment or not using [these variables](https://github.com/watson/is-ci/blob/master/index.js).
8+
9+
## AVA and connected client limits
10+
11+
You may be using a service that only allows a limited number of concurrent connections. For example, many database-as-a-service businesses offer a free plan with a limit on how many clients can be using it at the same time. AVA can hit those limits as it runs multiple processes, but well-written services should emit an error or throttle in those cases. If the one you're using doesn't, the tests will hang.
12+
13+
Use the `concurrency` flag to limit the number of processes ran. For example, if your service plan allows 5 clients, you should run AVA with `concurrency=5` or less.
14+
15+
## Async operations
16+
17+
You may be running an async operation inside a test and wondering why it's not finishing. If your async operation uses promises, you should return the promise:
18+
19+
```js
20+
test(t => {
21+
return fetch().then(data => {
22+
t.is(data, 'foo');
23+
});
24+
});
25+
```
26+
27+
If it uses callbacks, use [`test.cb`](https://github.com/avajs/ava#callback-support):
28+
29+
```js
30+
test.cb(t => {
31+
fetch((err, data) => {
32+
t.is(data, 'bar');
33+
t.end();
34+
});
35+
});
36+
```
37+
38+
Alternatively, promisify the callback function using something like [pify](https://github.com/sindresorhus/pify).
39+
40+
---
41+
42+
Is your problem not listed here? Submit a pull request or comment on [this issue](https://github.com/avajs/ava/issues/404).

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,10 @@ You can't use [`istanbul`](https://github.com/gotwarlost/istanbul) for code cove
968968

969969
As of version `5.0.0` it uses source maps to report coverage for your actual code, regardless of transpilation. Make sure that the code you're testing includes an inline source map or references a source map file. If you use `babel-register` you can set the `sourceMaps` option in your Babel config to `inline`.
970970

971+
### Common pitfalls
972+
973+
We have a growing list of [common pitfalls](docs/common-pitfalls.md) you may experience while using AVA. If you encounter any issues you think are common, comment in [this issue](https://github.com/avajs/ava/issues/404).
974+
971975
## FAQ
972976

973977
### Why not `mocha`, `tape`, `tap`?

0 commit comments

Comments
 (0)