UNPKG

7.93 kBMarkdownView Raw
1*[Please support our friend Vadim Demedes and the people in Ukraine.](https://stand-with-ukraine.pp.ua/)*
2
3---
4
5# <img src="media/header.png" title="AVA" alt="AVA logo" width="530">
6
7AVA is a test runner for Node.js with a concise API, detailed error output, embrace of new language features and thread isolation that lets you develop with confidence 🚀
8
9Watch this repository and follow the [Discussions](https://github.com/avajs/ava/discussions) for updates.
10
11Read our [contributing guide](.github/CONTRIBUTING.md) if you're looking to contribute (issues / PRs / etc).
12
13![](media/verbose-reporter.png)
14
15
16Translations: [Español](https://github.com/avajs/ava-docs/blob/main/es_ES/readme.md), [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/readme.md), [Italiano](https://github.com/avajs/ava-docs/blob/main/it_IT/readme.md), [日本語](https://github.com/avajs/ava-docs/blob/main/ja_JP/readme.md), [한국어](https://github.com/avajs/ava-docs/blob/main/ko_KR/readme.md), [Português](https://github.com/avajs/ava-docs/blob/main/pt_BR/readme.md), [Русский](https://github.com/avajs/ava-docs/blob/main/ru_RU/readme.md), [简体中文](https://github.com/avajs/ava-docs/blob/main/zh_CN/readme.md)
17
18
19## Why AVA?
20
21- Minimal and fast
22- Simple test syntax
23- Runs tests concurrently
24- Enforces writing atomic tests
25- No implicit globals
26- Includes TypeScript definitions
27- [Magic assert](#magic-assert)
28- [Isolated environment for each test file](./docs/01-writing-tests.md#test-isolation)
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 "type": "module",
51 "scripts": {
52 "test": "ava"
53 },
54 "devDependencies": {
55 "ava": "^5.0.0"
56 }
57}
58```
59
60Or if you prefer using Yarn:
61
62```console
63yarn add ava --dev
64```
65
66Alternatively you can install `ava` manually:
67
68```console
69npm install --save-dev ava
70```
71
72*Make sure to install AVA locally. AVA cannot be run globally.*
73
74Don't forget to configure the `test` script in your `package.json` as per above.
75
76### Create your test file
77
78Create a file named `test.js` in the project root directory.
79
80_Note that AVA's documentation assumes you're using ES modules._
81
82```js
83import test from 'ava';
84
85test('foo', t => {
86 t.pass();
87});
88
89test('bar', async t => {
90 const bar = Promise.resolve('bar');
91 t.is(await bar, 'bar');
92});
93```
94
95### Running your tests
96
97```console
98npm test
99```
100
101Or with `npx`:
102
103```console
104npx ava
105```
106
107Run with the `--watch` flag to enable AVA's [watch mode](docs/recipes/watch-mode.md):
108
109```console
110npx ava --watch
111```
112
113## Supported Node.js versions
114
115AVA 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).
116
117## Highlights
118
119### Magic assert
120
121AVA 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.
122
123![](media/magic-assert-combined.png)
124
125### Clean stack traces
126
127AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster, as seen above.
128
129### Parallel runs in CI
130
131AVA 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.
132
133## Documentation
134
135Please see the [files in the `docs` directory](./docs):
136
137* [Writing tests](./docs/01-writing-tests.md)
138* [Execution context](./docs/02-execution-context.md)
139* [Assertions](./docs/03-assertions.md)
140* [Snapshot testing](./docs/04-snapshot-testing.md)
141* [Command line (CLI)](./docs/05-command-line.md)
142* [Configuration](./docs/06-configuration.md)
143* [Test timeouts](./docs/07-test-timeouts.md)
144
145### Common pitfalls
146
147We 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).
148
149### Recipes
150
151- [Test setup](docs/recipes/test-setup.md)
152- [TypeScript](docs/recipes/typescript.md)
153- [Shared workers](docs/recipes/shared-workers.md)
154- [Watch mode](docs/recipes/watch-mode.md)
155- [When to use `t.plan()`](docs/recipes/when-to-use-plan.md)
156- [Passing arguments to your test files](docs/recipes/passing-arguments-to-your-test-files.md)
157- [Splitting tests in CI](docs/recipes/splitting-tests-ci.md)
158- [Code coverage](docs/recipes/code-coverage.md)
159- [Endpoint testing](docs/recipes/endpoint-testing.md)
160- [Browser testing](docs/recipes/browser-testing.md)
161- [Testing Vue.js components](docs/recipes/vue.md)
162- [Debugging tests with Chrome DevTools](docs/recipes/debugging-with-chrome-devtools.md)
163- [Debugging tests with VSCode](docs/recipes/debugging-with-vscode.md)
164- [Debugging tests with WebStorm](docs/recipes/debugging-with-webstorm.md)
165- [Isolated MongoDB integration tests](docs/recipes/isolated-mongodb-integration-tests.md)
166- [Testing web apps using Puppeteer](docs/recipes/puppeteer.md)
167- [Testing web apps using Selenium WebDriverJS](docs/recipes/testing-with-selenium-webdriverjs.md)
168
169## FAQ
170
171### How is the name written and pronounced?
172
173AVA, 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)
174
175### What is the header background?
176
177It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
178
179### What is the difference between concurrency and parallelism?
180
181[Concurrency is not parallelism. It enables parallelism.](https://stackoverflow.com/q/1050222)
182
183## Support
184
185- [GitHub Discussions](https://github.com/avajs/ava/discussions)
186
187## Related
188
189- [eslint-plugin-ava](https://github.com/avajs/eslint-plugin-ava) — Lint rules for AVA tests
190- [@ava/typescript](https://github.com/avajs/typescript) — Test TypeScript projects
191- [@ava/cooperate](https://github.com/avajs/cooperate) — Low-level primitives to enable cooperation between test files
192- [@ava/get-port](https://github.com/avajs/get-port) — Reserve a port while testing
193
194## Links
195
196- [AVA stickers, t-shirts, etc](https://www.redbubble.com/people/sindresorhus/works/30330590-ava-logo)
197- [Awesome list](https://github.com/avajs/awesome-ava)
198- [Do you like AVA? Donate here!](https://opencollective.com/ava)
199- [More…](https://github.com/avajs/awesome-ava)
200
201## Team
202
203[![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)
204---|---
205[Mark Wubben](https://novemberborn.net) | [Sindre Sorhus](https://sindresorhus.com)
206
207###### Former
208
209- [Kevin Mårtensson](https://github.com/kevva)
210- [James Talmage](https://github.com/jamestalmage)
211- [Juan Soto](https://github.com/sotojuan)
212- [Jeroen Engels](https://github.com/jfmengels)
213- [Vadim Demedes](https://github.com/vadimdemedes)
214
215
216<div align="center">
217 <br>
218 <br>
219 <br>
220 <a href="https://avajs.dev">
221 <img src="media/logo.svg" width="200" alt="AVA">
222 </a>
223 <br>
224 <br>
225</div>