AVA

Node.js test runner that lets you develop with confidence

README

SWUbanner

# AVA logo

AVA is a test runner for Node.js with a concise API, detailed error output, embrace of new language features and process isolation that lets you develop with confidence 🚀

Follow the AVA Twitter account for updates.

Read our contributing guide if you're looking to contribute (issues / PRs / etc).

undefined




Why AVA?


- Minimal and fast
- Simple test syntax
- Runs tests concurrently
- Enforces writing atomic tests
- No implicit globals
- Includes TypeScript definitions


Usage


To install and set up AVA, run:

  1. ```console
  2. npm init ava
  3. ```

Your package.json will then look like this (exact version notwithstanding):

  1. ```json
  2. {
  3. "name": "awesome-package",
  4. "scripts": {
  5.   "test": "ava"
  6. },
  7. "devDependencies": {
  8.   "ava": "^1.0.0"
  9. }
  10. }
  11. ```

Or if you prefer using Yarn:

  1. ```console
  2. yarn add ava --dev
  3. ```

Alternatively you can install ava manually:

  1. ```console
  2. npm install --save-dev ava
  3. ```

Make sure to install AVA locally. As of AVA 4 it can no longer be run globally.

Don't forget to configure the test script in your package.json as per above.

Create your test file


Create a file named test.js in the project root directory:

  1. ```js
  2. import test from 'ava';

  3. test('foo', t => {
  4. t.pass();
  5. });

  6. test('bar', async t => {
  7. const bar = Promise.resolve('bar');
  8. t.is(await bar, 'bar');
  9. });
  10. ```

Running your tests


  1. ```console
  2. npm test
  3. ```

Or with npx:

  1. ```console
  2. npx ava
  3. ```

Run with the --watch flag to enable AVA's watch mode:

  1. ```console
  2. npx ava --watch
  3. ```

Supported Node.js versions


AVA supports the latest release of any major version that is supported by Node.js itself. Read more in our support statement.

Highlights


Magic assert


AVA 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.

undefined

Clean stack traces


AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster, as seen above.

Parallel runs in CI


AVA 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.

Documentation


Please see the [files in the docs directory](./docs):


Common pitfalls


We have a growing list of common pitfalls you may experience while using AVA. If you encounter any issues you think are common, comment in this issue.

Recipes


- [When to use t.plan()](docs/recipes/when-to-use-plan.md)

FAQ


Why not mocha, tape, tap?


Mocha 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.

Tape and tap are pretty good. AVA is highly inspired by their syntax. They too execute tests serially. Their default TAP output isn't very user-friendly though so you always end up using an external tap reporter.

In 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.

How is the name written and pronounced?


AVA, not Ava or ava. Pronounced [/ˈeɪvə/](media/pronunciation.m4a?raw=true): Ay (face, made) V (vie, have) A (comma, ago)

What is the header background?



What is the difference between concurrency and parallelism?



Support



Related


- eslint-plugin-ava — Lint rules for AVA tests
- @ava/typescript — Test TypeScript projects
- @ava/cooperate — Low-level primitives to enable cooperation between test files
- @ava/get-port — Reserve a port while testing

Links



Team

Mark Wubben | Sindre Sorhus

Former






AVA