AVA

JavaScript 测试运行器。(JavaScript test runner)

Github stars Tracking Chart

测试可能是个累赘。AVA 会帮你搞定的。AVA 是 Node.js 的测试运行器,具有简洁的 API、详细的错误输出、支持新的语言特性和流程隔离,使您可以更有效地编写测试。这样你就可以发布更棒的代码。

关注AVA Twitter 账号更新。

如果您正在寻求贡献(问题 / PR / 等),请阅读我们的贡献指南

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

为何选择 AVA?

用法

请参考简体中文译文。(恕删略)

(First edition: vz edited at 2019.08.22)

Overview

Name With Owneravajs/ava
Primary LanguageJavaScript
Program languageJavaScript (Language Count: 3)
PlatformLinux, Mac, Windows
License:MIT License
Release Count114
Last Release Namev6.1.3 (Posted on 2024-05-05 22:34:08)
First Release Namev0.1.0 (Posted on 2015-08-28 16:22:03)
Created At2014-11-18 17:20:26
Pushed At2024-05-05 20:34:18
Last Commit At
Stargazers Count20.6k
Watchers Count227
Fork Count1.4k
Commits Count2k
Has Issues Enabled
Issues Count1652
Issue Open Count55
Pull Requests Count1063
Pull Requests Open Count3
Pull Requests Close Count370
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Build Status Coverage Status XO code style Join the community on Spectrum
Mentioned in Awesome Node.js

Testing 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. ?

Follow the AVA Twitter account 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",
	"scripts": {
		"test": "ava"
	},
	"devDependencies": {
		"ava": "^1.0.0"
	}
}

Or if you prefer using Yarn:

yarn add ava --dev

Alternatively you can install ava manually:

npm install --save-dev ava

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:

const test = require('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

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ə/: 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

Team

Mark Wubben, Sindre Sorhus, Vadim Demedes
---, ---, ---
Mark Wubben, Sindre Sorhus, Vadim Demedes

Former
To the top