Convert Figma logo to code with AI

avajs logoava

Node.js test runner that lets you develop with confidence 🚀

20,716
1,407
20,716
60

Top Related Projects

22,534

☕️ simple, flexible, fun javascript test framework for node.js & the browser

44,043

Delightful JavaScript Testing.

15,728

Simple JavaScript testing framework for browsers and node.js

5,769

tap-producing test harness for node and browsers

46,661

Fast, easy and reliable testing for anything that runs in a browser.

12,615

Next generation testing framework powered by Vite.

Quick Overview

AVA is a test runner for JavaScript that allows you to write tests in a concise and readable way. It is designed to be fast, parallel, and easy to use, making it a popular choice for developers working on Node.js and modern JavaScript projects.

Pros

  • Parallel Test Execution: AVA runs tests in parallel, which can significantly speed up the testing process, especially for larger projects.
  • Readable and Concise Syntax: AVA's syntax is designed to be intuitive and easy to read, with a focus on simplicity and clarity.
  • Powerful Assertion Library: AVA includes a powerful assertion library that provides a wide range of assertion methods, making it easy to write comprehensive tests.
  • Supports Modern JavaScript: AVA supports the latest features of JavaScript, including async/await, ES modules, and TypeScript, making it a great choice for modern JavaScript projects.

Cons

  • Limited Ecosystem: Compared to some other test runners, AVA has a smaller ecosystem of plugins and integrations, which may limit its flexibility for certain use cases.
  • Steep Learning Curve: While AVA's syntax is designed to be intuitive, the overall testing approach and configuration can have a steeper learning curve for developers who are new to the tool.
  • Limited Debugging Support: AVA's parallel test execution can make it more challenging to debug failing tests, especially for complex or asynchronous code.
  • Compatibility Issues: AVA's support for modern JavaScript features may cause compatibility issues with older Node.js versions or legacy projects.

Code Examples

Here are a few examples of how to use AVA:

Basic Test:

import test from 'ava';

test('addition', t => {
  const x = 2;
  const y = 3;
  t.is(x + y, 5);
});

Async Test:

import test from 'ava';

test('async addition', async t => {
  const x = 2;
  const y = 3;
  t.is(await addAsync(x, y), 5);
});

function addAsync(x, y) {
  return new Promise(resolve => {
    setTimeout(() => {
      resolve(x + y);
    }, 1000);
  });
}

Snapshot Test:

import test from 'ava';

test('snapshot', t => {
  const value = {
    foo: 'bar',
    baz: 42
  };
  t.snapshot(value);
});

TypeScript Test:

import test from 'ava';

test('addition', t => {
  const x: number = 2;
  const y: number = 3;
  t.is(x + y, 5);
});

Getting Started

To get started with AVA, follow these steps:

  1. Install AVA as a development dependency in your project:

    npm install --save-dev ava
    
  2. Create an ava.config.js file in the root of your project to configure AVA:

    export default {
      files: ['**/*.test.js', '**/*.spec.js'],
      extensions: ['js', 'mjs', 'cjs', 'ts', 'tsx'],
      require: ['esm']
    };
    
  3. Write your first test in a file named example.test.js:

    import test from 'ava';
    
    test('addition', t => {
      const x = 2;
      const y = 3;
      t.is(x + y, 5);
    });
    
  4. Run your tests using the AVA CLI:

    npx ava
    

That's it! You've now set up AVA in your project and written your first test. You can continue to add more tests, configure AVA to fit your needs, and explore the many features and plugins available for the tool.

Competitor Comparisons

22,534

☕️ simple, flexible, fun javascript test framework for node.js & the browser

Pros of Mocha

  • More flexible and customizable test structure
  • Extensive ecosystem with a wide range of plugins and extensions
  • Better suited for complex, asynchronous testing scenarios

Cons of Mocha

  • Slower test execution compared to AVA
  • Requires additional assertion libraries and mocking tools
  • More verbose test syntax, potentially leading to longer test files

Code Comparison

Mocha:

describe('Array', function() {
  describe('#indexOf()', function() {
    it('should return -1 when the value is not present', function() {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});

AVA:

test('Array#indexOf()', t => {
  t.is([1, 2, 3].indexOf(4), -1);
});

Summary

Mocha offers greater flexibility and a rich ecosystem, making it suitable for complex testing scenarios. However, it can be slower and requires additional setup. AVA, on the other hand, provides a simpler, more concise syntax and faster test execution but may lack some of the advanced features and customization options available in Mocha. The choice between the two depends on the specific needs of the project and the development team's preferences.

44,043

Delightful JavaScript Testing.

Pros of Jest

  • Built-in code coverage and mocking capabilities
  • Snapshot testing for UI components
  • Parallel test execution for faster performance

Cons of Jest

  • Slower startup time, especially for smaller projects
  • More complex configuration for advanced use cases
  • Larger package size and more dependencies

Code Comparison

AVA example:

import test from 'ava';

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

Jest example:

test('foo', () => {
    expect(true).toBe(true);
});

Both AVA and Jest are popular JavaScript testing frameworks, but they have different approaches and features. Jest offers a more comprehensive out-of-the-box experience with built-in mocking, code coverage, and snapshot testing. It's particularly well-suited for React projects and larger applications.

AVA, on the other hand, focuses on simplicity and speed. It has a minimal API, runs tests concurrently, and is designed to be lightweight. AVA is often preferred for smaller projects or when developers want more control over their testing setup.

The code comparison shows that both frameworks have a straightforward syntax for writing tests, but AVA uses an imported test function and an assertion object, while Jest relies on global functions and a more expressive expectation API.

15,728

Simple JavaScript testing framework for browsers and node.js

Pros of Jasmine

  • Widely adopted and well-established in the JavaScript testing ecosystem
  • Built-in assertion library and mocking capabilities
  • Supports both browser and Node.js environments out of the box

Cons of Jasmine

  • Slower test execution compared to AVA's parallel test running
  • Less modern syntax and features compared to AVA's ES6+ support
  • Lacks built-in TypeScript support, which AVA provides

Code Comparison

Jasmine test example:

describe('Calculator', () => {
  it('should add two numbers', () => {
    expect(add(2, 3)).toBe(5);
  });
});

AVA test example:

import test from 'ava';

test('add two numbers', t => {
  t.is(add(2, 3), 5);
});

Both AVA and Jasmine are popular testing frameworks for JavaScript projects. AVA focuses on simplicity, speed, and modern JavaScript features, while Jasmine offers a more traditional BDD-style syntax and broader ecosystem support. AVA's parallel test execution and built-in TypeScript support make it attractive for projects prioritizing performance and type safety. Jasmine's maturity and wide adoption make it a solid choice for projects that value stability and extensive community resources.

5,769

tap-producing test harness for node and browsers

Pros of tape

  • Simpler and more lightweight, with minimal setup required
  • Follows Unix philosophy of doing one thing well
  • Easier to understand and debug due to its straightforward approach

Cons of tape

  • Lacks built-in features like concurrent test execution
  • Limited assertion library compared to AVA's more extensive options
  • Doesn't provide built-in code coverage or watch mode functionality

Code Comparison

tape:

const test = require('tape');

test('basic arithmetic', (t) => {
  t.equal(2 + 2, 4, 'addition works');
  t.end();
});

AVA:

import test from 'ava';

test('basic arithmetic', (t) => {
  t.is(2 + 2, 4, 'addition works');
});

Both tape and AVA offer simple syntax for writing tests, but AVA provides more built-in features and a richer assertion library. tape follows a more minimalist approach, requiring less setup but potentially more manual configuration for advanced features. AVA is designed for larger projects with concurrent test execution, while tape is ideal for smaller projects or those preferring a simpler testing framework.

46,661

Fast, easy and reliable testing for anything that runs in a browser.

Pros of Cypress

  • Provides an interactive test runner with real-time reloading and debugging capabilities
  • Offers built-in waiting mechanisms and automatic retries for more stable tests
  • Includes comprehensive documentation and a large, active community

Cons of Cypress

  • Limited to testing web applications only, unlike AVA's broader JavaScript testing capabilities
  • Can be slower to execute tests compared to AVA, especially for large test suites
  • Requires more setup and configuration for certain scenarios, while AVA aims for simplicity

Code Comparison

AVA:

import test from 'ava';

test('my test', t => {
  t.is(1 + 1, 2);
});

Cypress:

describe('My Test', () => {
  it('performs a simple calculation', () => {
    expect(1 + 1).to.equal(2);
  });
});

Summary

Cypress excels in end-to-end testing for web applications, offering a rich interactive experience and built-in stability features. AVA, on the other hand, is a lightweight and fast test runner for general JavaScript testing, focusing on simplicity and parallel test execution. While Cypress provides a more comprehensive solution for web testing, AVA offers greater flexibility for various JavaScript projects beyond the browser environment.

12,615

Next generation testing framework powered by Vite.

Pros of Vitest

  • Faster execution due to native ESM support and Vite's HMR capabilities
  • Better integration with Vue.js ecosystem and Vite-based projects
  • Out-of-the-box TypeScript support without additional configuration

Cons of Vitest

  • Less mature ecosystem compared to AVA's established community
  • Limited compatibility with older Node.js versions and non-ESM projects
  • Fewer built-in assertions and helpers compared to AVA's extensive set

Code Comparison

AVA:

import test from 'ava';

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

Vitest:

import { test, expect } from 'vitest';

test('foo', () => {
    expect(true).toBe(true);
});

Both frameworks offer a clean and straightforward syntax for writing tests. AVA uses its own assertion methods (like t.pass()), while Vitest leverages a Jest-like API with expect() assertions. Vitest's syntax may be more familiar to developers coming from Jest or other similar testing frameworks.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Please support our friend Vadim Demedes and the people in Ukraine.


AVA logo

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

Watch this repository and follow the Discussions for updates.

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

Translations: Español, Français, Italiano, 日本語, 한국어, Português, Русский, 简体中文

Why AVA?

Usage

To install and set up AVA, run:

npm init ava

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

{
	"name": "awesome-package",
	"type": "module",
	"scripts": {
		"test": "ava"
	},
	"devDependencies": {
		"ava": "^5.0.0"
	}
}

Or if you prefer using Yarn:

yarn add ava --dev

Alternatively you can install ava manually:

npm install --save-dev ava

Make sure to install AVA locally. AVA cannot 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.

Note that AVA's documentation assumes you're using ES modules.

import test from 'ava';

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

test('bar', async t => {
	const bar = Promise.resolve('bar');
	t.is(await bar, 'bar');
});

Running your tests

npm test

Or with npx:

npx ava

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

npx ava --watch

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.

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 package for a list of supported CI environments.

Documentation

Please see the files in the docs directory:

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

FAQ

How is the name written and pronounced?

AVA, not Ava or ava. Pronounced /ˈeɪvə/: Ay (face, made) V (vie, have) A (comma, ago)

What is the header background?

It's the Andromeda galaxy.

What is the difference between concurrency and parallelism?

Concurrency is not parallelism. It enables parallelism.

Support

Related

Links

Team

Mark WubbenSindre Sorhus
Mark WubbenSindre Sorhus
Former

NPM DownloadsLast 30 Days