ava README

The project's README from github.com/avajs/ava. As one markdown file: README.md.

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

Team

Mark Wubben Sindre Sorhus
Mark Wubben Sindre Sorhus
Former



AVA

ava (avajs/ava)

Searching Database…

20.8K ·GitHub
这是什么?AVA 是一个 Node.js 测试运行器:它用简洁的 API 运行你的测试,提供详细的错误输出和线程隔离,让你可以放心地开发。
它是我导入到代码里的库,还是我运行的工具?是一个命令行工具:你把它安装到项目里,它会通过 package.json 中的 test 脚本运行你的测试文件(也可以直接用 npx ava 运行)。
我怎么把它跑起来?先用 npm 或 Yarn 在本地安装,在 package.json 里配置 test 脚本,在项目根目录创建一个 test.js 文件,然后用 npx ava 运行测试——加上 --watch 标志,编辑代码时就会自动重新运行。
使用它需要安装什么?只需要 Node.js 本身——AVA 支持 Node.js 所支持的各大版本的最新发行版(它的 engines 字段目前要求 ^22.20、^24.12 或 >=26)。
安装有什么坑吗?有——AVA 不能全局运行,必须在每个项目里本地安装。文档还默认你在使用 ES modules,官方也维护了一份常见坑的清单。
和其他 Node.js 测试运行器相比,为什么选 AVA?测试并发运行,每个测试文件都有隔离的环境,所以速度快而且相互独立;它不允许隐式全局变量,会把堆栈跟踪里无关的行清理掉,还能自动把测试文件分配到并行的 CI 构建中。内置了 TAP 报告器。
'magic assert' 是什么?AVA 的断言输出会显示代码片段,以及实际值和期望值之间干净的差异对比。对于对象和数组,它只显示有差异的部分,并带语法高亮;对于字符串,它会精确标出哪些字符是新增的、哪些是缺失的。
我可以用 TypeScript 写测试吗?可以——TypeScript 类型定义开箱即用,文档里有 TypeScript 配方,还有一个专门用于测试 TypeScript 项目的配套包 @ava/typescript。
除了普通的单元测试,我还能测什么?官方配方涵盖了接口测试、用 Puppeteer 或 Selenium 做浏览器测试、Vue.js 组件、隔离的 MongoDB 集成测试、代码覆盖率,以及用 Chrome DevTools、VSCode 或 WebStorm 调试测试。
What are similar projects?testify, enzyme, mocha, pytest, karma, jasmine, jest, zenc
Creator
avajs
Size
14.4 MB
Stars
20.8K
Age
11y
Commits · 90 Days