UNPKG

10.4 kBMarkdownView Raw
1# <img src="media/header.png" title="AVA" alt="AVA logo" width="530">
2
3[![Build Status](https://travis-ci.org/avajs/ava.svg?branch=master)](https://travis-ci.org/avajs/ava) [![Coverage Status](https://codecov.io/gh/avajs/ava/branch/master/graph/badge.svg)](https://codecov.io/gh/avajs/ava/branch/master) [![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo) [![Join the community on Spectrum](https://withspectrum.github.io/badge/badge.svg)](https://spectrum.chat/ava)
4[![Mentioned in Awesome Node.js](https://awesome.re/mentioned-badge.svg)](https://github.com/sindresorhus/awesome-nodejs)
5
6Testing can be a drag. AVA helps you get it done. AVA is a test runner for Node.js with a concise API, detailed error output, embrace of new language features and process isolation that let you write tests more effectively. So you can ship more awesome code. 🚀
7
8Follow the [AVA Twitter account](https://twitter.com/ava__js) for updates.
9
10Read our [contributing guide](contributing.md) if you're looking to contribute (issues / PRs / etc).
11
12![](media/mini-reporter.gif)
13
14
15Translations: [Español](https://github.com/avajs/ava-docs/blob/master/es_ES/readme.md), [Français](https://github.com/avajs/ava-docs/blob/master/fr_FR/readme.md), [Italiano](https://github.com/avajs/ava-docs/blob/master/it_IT/readme.md), [日本語](https://github.com/avajs/ava-docs/blob/master/ja_JP/readme.md), [한국어](https://github.com/avajs/ava-docs/blob/master/ko_KR/readme.md), [Português](https://github.com/avajs/ava-docs/blob/master/pt_BR/readme.md), [Русский](https://github.com/avajs/ava-docs/blob/master/ru_RU/readme.md), [简体中文](https://github.com/avajs/ava-docs/blob/master/zh_CN/readme.md)
16
17
18## Why AVA?
19
20- Minimal and fast
21- Simple test syntax
22- Runs tests concurrently
23- Enforces writing atomic tests
24- No implicit globals
25- Includes TypeScript definitions
26- [Magic assert](#magic-assert)
27- [Isolated environment for each test file](./docs/01-writing-tests.md#process-isolation)
28- [Write your tests using the latest JavaScript syntax](#latest-javascript-support)
29- [Promise support](./docs/01-writing-tests.md#promise-support)
30- [Async function support](./docs/01-writing-tests.md#async-function-support)
31- [Observable support](./docs/01-writing-tests.md#observable-support)
32- [Enhanced assertion messages](./docs/03-assertions.md#enhanced-assertion-messages)
33- [Automatic parallel test runs in CI](#parallel-runs-in-ci)
34- [TAP reporter](./docs/05-command-line.md#tap-reporter)
35
36
37## Usage
38
39To install and set up AVA, run:
40
41```console
42npm init ava
43```
44
45Your `package.json` will then look like this (exact version notwithstanding):
46
47```json
48{
49 "name": "awesome-package",
50 "scripts": {
51 "test": "ava"
52 },
53 "devDependencies": {
54 "ava": "^1.0.0"
55 }
56}
57```
58
59Or if you prefer using Yarn:
60
61```console
62yarn add ava --dev
63```
64
65Alternatively you can install `ava` manually:
66
67```console
68npm install --save-dev ava
69```
70
71Don't forget to configure the `test` script in your `package.json` as per above.
72
73### Create your test file
74
75Create a file named `test.js` in the project root directory:
76
77```js
78import test from 'ava';
79
80test('foo', t => {
81 t.pass();
82});
83
84test('bar', async t => {
85 const bar = Promise.resolve('bar');
86 t.is(await bar, 'bar');
87});
88```
89
90### Running your tests
91
92```console
93npm test
94```
95
96Or with `npx`:
97
98```console
99npx ava
100```
101
102Run with the `--watch` flag to enable AVA's [watch mode](docs/recipes/watch-mode.md):
103
104```console
105npx ava --watch
106```
107
108## Supported Node.js versions
109
110AVA supports the latest release of any major version that [is supported by Node.js itself](https://github.com/nodejs/Release#release-schedule). Read more in our [support statement](docs/support-statement.md).
111
112## Highlights
113
114### Magic assert
115
116AVA adds code excerpts and clean diffs for actual and expected values. If values in the assertion are objects or arrays, only a diff is displayed, to remove the noise and focus on the problem. The diff is syntax-highlighted too! If you are comparing strings, both single and multi line, AVA displays a different kind of output, highlighting the added or missing characters.
117
118![](media/magic-assert-combined.png)
119
120### Clean stack traces
121
122AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster, as seen above.
123
124### Latest JavaScript support
125
126AVA uses [Babel 7](https://babeljs.io) so you can use the latest JavaScript syntax in your tests. There is no extra setup required. You don't need to be using Babel in your own project for this to work either.
127
128We aim to support all [finished syntax proposals](https://github.com/tc39/proposals/blob/master/finished-proposals.md), as well as all syntax from ratified JavaScript versions (e.g. ES2017). See our [`@ava/stage-4`](https://github.com/avajs/babel-preset-stage-4) preset for the currently supported proposals.
129
130Please note that we do not add or modify built-ins. For example, if you use [`Object.fromEntries()`](https://github.com/tc39/proposal-object-from-entries) in your tests, they will crash in Node.js 10 which does not implement this method.
131
132You can disable this syntax support, or otherwise customize AVA's Babel pipeline. See our [Babel recipe] for more details.
133
134### Parallel runs in CI
135
136AVA automatically detects whether your CI environment supports parallel builds. Each build will run a subset of all test files, while still making sure all tests get executed. See the [`ci-parallel-vars`](https://www.npmjs.com/package/ci-parallel-vars) package for a list of supported CI environments.
137
138## Documentation
139
140Please see the [files in the `docs` directory](./docs):
141
142* [Writing tests](./docs/01-writing-tests.md)
143* [Execution context](./docs/02-execution-context.md)
144* [Assertions](./docs/03-assertions.md)
145* [Snapshot testing](./docs/04-snapshot-testing.md)
146* [Command line (CLI)](./docs/05-command-line.md)
147* [Configuration](./docs/06-configuration.md)
148* [Test timeouts](./docs/07-test-timeouts.md)
149
150### Common pitfalls
151
152We have a growing list of [common pitfalls](docs/08-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).
153
154### Recipes
155
156- [Test setup](docs/recipes/test-setup.md)
157- [Code coverage](docs/recipes/code-coverage.md)
158- [Watch mode](docs/recipes/watch-mode.md)
159- [Endpoint testing](docs/recipes/endpoint-testing.md)
160- [When to use `t.plan()`](docs/recipes/when-to-use-plan.md)
161- [Browser testing](docs/recipes/browser-testing.md)
162- [TypeScript](docs/recipes/typescript.md)
163- [Flow](docs/recipes/flow.md)
164- [Configuring Babel][Babel recipe]
165- [Using ES modules](docs/recipes/es-modules.md)
166- [Passing arguments to your test files](docs/recipes/passing-arguments-to-your-test-files.md)
167- [Testing React components](docs/recipes/react.md)
168- [Testing Vue.js components](docs/recipes/vue.md)
169- [JSPM and SystemJS](docs/recipes/jspm-systemjs.md)
170- [Debugging tests with Chrome DevTools](docs/recipes/debugging-with-chrome-devtools.md)
171- [Debugging tests with VSCode](docs/recipes/debugging-with-vscode.md)
172- [Debugging tests with WebStorm](docs/recipes/debugging-with-webstorm.md)
173- [Isolated MongoDB integration tests](docs/recipes/isolated-mongodb-integration-tests.md)
174- [Testing web apps using Puppeteer](docs/recipes/puppeteer.md)
175
176## FAQ
177
178### Why not `mocha`, `tape`, `tap`?
179
180Mocha requires you to use implicit globals like `describe` and `it` with the default interface (which most people use). It's not very opinionated and executes tests serially without process isolation, making it slow.
181
182Tape and tap are pretty good. AVA is highly inspired by their syntax. They too execute tests serially. Their default [TAP](https://testanything.org) output isn't very user-friendly though so you always end up using an external tap reporter.
183
184In contrast AVA is highly opinionated and runs tests concurrently, with a separate process for each test file. Its default reporter is easy on the eyes and yet AVA still supports TAP output through a CLI flag.
185
186### How is the name written and pronounced?
187
188AVA, not Ava or ava. Pronounced [`/ˈeɪvə/`](media/pronunciation.m4a?raw=true): Ay (f**a**ce, m**a**de) V (**v**ie, ha**v**e) A (comm**a**, **a**go)
189
190### What is the header background?
191
192It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
193
194### What is the difference between concurrency and parallelism?
195
196[Concurrency is not parallelism. It enables parallelism.](https://stackoverflow.com/q/1050222)
197
198## Support
199
200- [Stack Overflow](https://stackoverflow.com/questions/tagged/ava)
201- [Spectrum](https://spectrum.chat/ava)
202- [Twitter](https://twitter.com/ava__js)
203
204## Related
205
206- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) - Lint rules for AVA tests
207- [sublime-ava](https://github.com/avajs/sublime-ava) - Snippets for AVA tests
208- [atom-ava](https://github.com/avajs/atom-ava) - Snippets for AVA tests
209- [vscode-ava](https://github.com/samverschueren/vscode-ava) - Snippets for AVA tests
210- [gulp-ava](https://github.com/avajs/gulp-ava) - Run tests with gulp
211- [grunt-ava](https://github.com/avajs/grunt-ava) - Run tests with grunt
212- [More…](https://github.com/avajs/awesome-ava#packages)
213
214## Links
215
216- [AVA stickers, t-shirts, etc](https://www.redbubble.com/people/sindresorhus/works/30330590-ava-logo)
217- [Awesome list](https://github.com/avajs/awesome-ava)
218- [AVA Casts](http://avacasts.com)
219- [More…](https://github.com/avajs/awesome-ava)
220
221## Team
222
223[![Mark Wubben](https://github.com/novemberborn.png?size=100)](https://github.com/novemberborn) | [![Sindre Sorhus](https://github.com/sindresorhus.png?size=100)](https://github.com/sindresorhus) | [![Vadim Demedes](https://github.com/vadimdemedes.png?size=100)](https://github.com/vadimdemedes)
224---|---|---
225[Mark Wubben](https://novemberborn.net) | [Sindre Sorhus](http://sindresorhus.com) | [Vadim Demedes](https://github.com/vadimdemedes)
226
227###### Former
228
229- [Kevin Mårtensson](https://github.com/kevva)
230- [James Talmage](https://github.com/jamestalmage)
231- [Juan Soto](https://github.com/sotojuan)
232- [Jeroen Engels](https://github.com/jfmengels)
233
234
235<div align="center">
236 <br>
237 <br>
238 <br>
239 <a href="https://ava.li">
240 <img src="media/logo.svg" width="200" alt="AVA">
241 </a>
242 <br>
243 <br>
244</div>
245
246[Babel recipe]: docs/recipes/babel.md