Skip to content
/ ava Public
forked from avajs/ava

Node.js test runner that lets you develop with confidence ๐Ÿš€

License

Notifications You must be signed in to change notification settings

zkhin/ava

 
 

Repository files navigation

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

Examples and Use Cases

Here are some examples and use cases to help you understand how to use AVA effectively:

Example 1: Testing a simple function

import test from 'ava';

function add(a, b) {
	return a + b;
}

test('add() should return the sum of two numbers', t => {
	t.is(add(2, 3), 5);
	t.is(add(-1, 1), 0);
});

Example 2: Testing asynchronous code

import test from 'ava';

async function fetchData() {
	return new Promise(resolve => {
		setTimeout(() => {
			resolve('data');
		}, 1000);
	});
}

test('fetchData() should return data', async t => {
	const data = await fetchData();
	t.is(data, 'data');
});

Example 3: Testing with snapshots

import test from 'ava';

function getUser() {
	return {
		name: 'John Doe',
		age: 30,
	};
}

test('getUser() should return the correct user object', t => {
	t.snapshot(getUser());
});

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 Wubben Sindre Sorhus
Mark Wubben Sindre Sorhus
Former

Contributing

We welcome contributions from the community! Here are some ways you can contribute:

  1. Improve Documentation: Help us improve our documentation by fixing typos, adding examples, or providing better explanations.
  2. Report Issues: If you find a bug or have a feature request, please open an issue on GitHub.
  3. Submit Pull Requests: If you have a fix or a new feature, submit a pull request. Make sure to follow our coding guidelines and include tests for your changes.
  4. Give Feedback: Participate in discussions on GitHub to provide feedback on issues and pull requests.
  5. Help with Tests: Write tests to improve our test coverage and ensure the stability of the project.

For more detailed guidelines, please refer to our contributing guide.

About

Node.js test runner that lets you develop with confidence ๐Ÿš€

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 90.5%
  • TypeScript 9.4%
  • Shell 0.1%