-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document common pitfalls #919
Changes from 6 commits
ba855b6
0db5273
129e806
d663cd6
a777ffd
c9fa25c
da9c034
96685ba
349543f
6434804
10cb03b
b79f347
6d71cbe
f4a179c
691cecc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Common Pitfalls | ||
|
||
## AVA in Docker | ||
|
||
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). | ||
|
||
AVA uses [is-ci](https://github.com/watson/is-ci) to decide if it's in a CI environment or not using [these](https://github.com/watson/is-ci/blob/master/index.js) variables. | ||
|
||
## AVA and connected client limits | ||
|
||
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. | ||
|
||
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. | ||
|
||
## Async operations | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened an issue about this: avajs/eslint-plugin-ava#122 We should really try to detect this at runtime and in our ESLint plugin too. |
||
|
||
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 be returning the promise: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "you should return the promise" |
||
|
||
```js | ||
test(t => { | ||
return fetch().then(data => { | ||
t.is(data, 'foo'); | ||
}); | ||
}); | ||
``` | ||
|
||
If it uses callbacks, use [`test.cb`](https://github.com/avajs/ava#callback-support): | ||
|
||
```js | ||
test.cb(t => { | ||
fetch((err, data) => { | ||
t.is(data, 'bar'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should advise promisifying the function. Assertion failures would throw, which depending on the async function's implementation may cause an uncaught exception. Also you'd need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should recommend promisifying, but still show both solutions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Our assertions don't throw after being enhanced. test('foo', t => {
t.is(1, 2);
console.log('foo'); // this will get printed.
}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, but the next assertion could try to access a property of a |
||
}); | ||
}); | ||
``` | ||
|
||
--- | ||
|
||
Is your problem not listed here? Submit a pull request or comment on [this](https://github.com/avajs/ava/issues/404) issue. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here linking "this issue". |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe link
these variables
? It makes the link more descriptive.