-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Document common pitfalls #919
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
Changes from 10 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,42 @@ | ||
| # 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 variables](https://github.com/watson/is-ci/blob/master/index.js). | ||
|
|
||
| ## 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 | ||
|
|
||
| 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: | ||
|
|
||
| ```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'); | ||
|
Member
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
Member
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.
Contributor
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.
});
Member
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 |
||
| t.end(); | ||
| }); | ||
| }); | ||
| ``` | ||
|
|
||
| Alternatively, promisify the callback function using something like [pify](https://github.com/sindresorhus/pify). | ||
|
|
||
| --- | ||
|
|
||
| Is your problem not listed here? Submit a pull request or comment on [this issue](https://github.com/avajs/ava/issues/404). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,13 +68,13 @@ $ ava --init | |
|
|
||
| ```json | ||
| { | ||
| "name": "awesome-package", | ||
| "scripts": { | ||
| "test": "ava" | ||
| }, | ||
| "devDependencies": { | ||
| "ava": "^0.11.0" | ||
| } | ||
| "name": "awesome-package", | ||
|
||
| "scripts": { | ||
| "test": "ava" | ||
| }, | ||
| "devDependencies": { | ||
| "ava": "^0.11.0" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -132,33 +132,33 @@ AVA comes with an intelligent watch mode. [Learn more in its recipe](docs/recipe | |
| ```console | ||
| $ ava --help | ||
|
|
||
| Usage | ||
| ava [<file|directory|glob> ...] | ||
|
|
||
| Options | ||
| --init Add AVA to your project | ||
| --fail-fast Stop after first test failure | ||
| --serial, -s Run tests serially | ||
| --require, -r Module to preload (Can be repeated) | ||
| --tap, -t Generate TAP output | ||
| --verbose, -v Enable verbose output | ||
| --no-cache Disable the transpiler cache | ||
| --match, -m Only run tests with matching title (Can be repeated) | ||
| --watch, -w Re-run tests when tests and source files change | ||
| --source, -S Pattern to match source files so tests can be re-run (Can be repeated) | ||
| --timeout, -T Set global timeout | ||
| --concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL) | ||
|
|
||
| Examples | ||
| ava | ||
| ava test.js test2.js | ||
| ava test-*.js | ||
| ava test | ||
| ava --init | ||
| ava --init foo.js | ||
|
|
||
| Default patterns when no arguments: | ||
| test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js | ||
| Usage | ||
| ava [<file|directory|glob> ...] | ||
|
|
||
| Options | ||
| --init Add AVA to your project | ||
| --fail-fast Stop after first test failure | ||
| --serial, -s Run tests serially | ||
| --require, -r Module to preload (Can be repeated) | ||
| --tap, -t Generate TAP output | ||
| --verbose, -v Enable verbose output | ||
| --no-cache Disable the transpiler cache | ||
| --match, -m Only run tests with matching title (Can be repeated) | ||
| --watch, -w Re-run tests when tests and source files change | ||
| --source, -S Pattern to match source files so tests can be re-run (Can be repeated) | ||
| --timeout, -T Set global timeout | ||
| --concurrency, -c Maximum number of test files running at the same time (EXPERIMENTAL) | ||
|
|
||
| Examples | ||
| ava | ||
| ava test.js test2.js | ||
| ava test-*.js | ||
| ava test | ||
| ava --init | ||
| ava --init foo.js | ||
|
|
||
| Default patterns when no arguments: | ||
| test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js | ||
| ``` | ||
|
|
||
| *Note that the CLI will use your local install of AVA when available, even when run globally.* | ||
|
|
@@ -173,27 +173,27 @@ All of the CLI options can be configured in the `ava` section of your `package.j | |
|
|
||
| ```json | ||
| { | ||
| "ava": { | ||
| "files": [ | ||
| "my-test-folder/*.js", | ||
| "!**/not-this-file.js" | ||
| ], | ||
| "source": [ | ||
| "**/*.{js,jsx}", | ||
| "!dist/**/*" | ||
| ], | ||
| "match": [ | ||
| "*oo", | ||
| "!foo" | ||
| ], | ||
| "concurrency": 5, | ||
| "failFast": true, | ||
| "tap": true, | ||
| "require": [ | ||
| "babel-register" | ||
| ], | ||
| "babel": "inherit" | ||
| } | ||
| "ava": { | ||
| "files": [ | ||
| "my-test-folder/*.js", | ||
| "!**/not-this-file.js" | ||
| ], | ||
| "source": [ | ||
| "**/*.{js,jsx}", | ||
| "!dist/**/*" | ||
| ], | ||
| "match": [ | ||
| "*oo", | ||
| "!foo" | ||
| ], | ||
| "concurrency": 5, | ||
| "failFast": true, | ||
| "tap": true, | ||
| "require": [ | ||
| "babel-register" | ||
| ], | ||
| "babel": "inherit" | ||
| } | ||
|
||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -610,14 +610,14 @@ The corresponding Babel config for AVA's setup is as follows: | |
|
|
||
| ```json | ||
| { | ||
| "presets": [ | ||
| "es2015", | ||
| "stage-2" | ||
| ], | ||
| "plugins": [ | ||
| "espower", | ||
| "transform-runtime" | ||
| ] | ||
| "presets": [ | ||
| "es2015", | ||
| "stage-2" | ||
| ], | ||
| "plugins": [ | ||
| "espower", | ||
| "transform-runtime" | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
|
|
@@ -935,9 +935,9 @@ Will output: | |
|
|
||
| ``` | ||
| t.true(a.test(b) || b === c) | ||
| | | | | | ||
| | "bar" "bar" "baz" | ||
| false | ||
| | | | | | ||
| | "bar" "bar" "baz" | ||
| false | ||
| ``` | ||
|
|
||
| ## Process isolation | ||
|
|
@@ -966,6 +966,10 @@ You can't use [`istanbul`](https://github.com/gotwarlost/istanbul) for code cove | |
|
|
||
| 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`. | ||
|
|
||
| ### Common pitfalls | ||
|
|
||
| We have a growing list of [common pitfalls](https://github.com/avajs/ava/blob/master/docs/common-pitfalls.md) you may experience while using AVA. If you encounter any issues you think are common, comment on [this issue](https://github.com/avajs/ava/issues/404). | ||
|
||
|
|
||
| ## FAQ | ||
|
|
||
| ### Why not `mocha`, `tape`, `tap`? | ||
|
|
||
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.
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.