Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
AVA is a test runner for Node.js with a concise API, detailed error output, and process isolation that allows for fast and reliable testing. It supports asynchronous testing, and its design encourages writing tests that run concurrently.
Concurrent Test Execution
AVA runs tests concurrently, which can lead to faster test execution. The example shows two tests, one synchronous and one asynchronous, both of which will run concurrently.
const test = require('ava');
test('foo', t => {
t.pass();
});
test('bar', async t => {
const bar = Promise.resolve('bar');
t.is(await bar, 'bar');
});
Snapshot Testing
AVA supports snapshot testing, which allows you to save the output of your tests and compare it to future test runs. This is useful for ensuring that your code's output remains consistent over time.
const test = require('ava');
test('snapshot', t => {
const obj = {foo: 'bar'};
t.snapshot(obj);
});
Power Assert
AVA uses power-assert to provide detailed assertion messages, making it easier to understand why a test failed. The example shows a failing test with a clear assertion message.
const test = require('ava');
test('power assert', t => {
const x = 'foo';
t.is(x, 'bar');
});
Test Isolation
AVA ensures that each test runs in isolation, preventing side effects from affecting other tests. The example shows how `t.context` can be used to set up data for each test.
const test = require('ava');
test.beforeEach(t => {
t.context.data = {foo: 'bar'};
});
test('test 1', t => {
t.context.data.foo = 'baz';
t.is(t.context.data.foo, 'baz');
});
test('test 2', t => {
t.is(t.context.data.foo, 'bar');
});
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. It provides a variety of interfaces (e.g., BDD, TDD) and supports both synchronous and asynchronous testing. Compared to AVA, Mocha is more flexible but requires more configuration to achieve similar functionality.
Jest is a delightful JavaScript Testing Framework with a focus on simplicity. It works out of the box for most JavaScript projects and includes features like snapshot testing, a built-in mocking library, and code coverage. Jest is more opinionated than AVA and provides a more integrated experience, especially for React applications.
Tape is a tap-producing test harness for Node.js and browsers. It is minimalistic and focuses on providing a simple API for writing tests. Tape does not include features like test runners or reporters, which makes it less feature-rich compared to AVA but also simpler and more lightweight.
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, Русский, 简体中文
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 a file named test.js
in the project root directory:
import test from 'ava';
test('foo', t => {
t.pass();
});
test('bar', async t => {
const bar = Promise.resolve('bar');
t.is(await bar, 'bar');
});
npm test
Or with npx
:
npx ava
Run with the --watch
flag to enable AVA's watch mode:
npx ava --watch
AVA supports the latest release of any major version that is supported by Node.js itself. Read more in our support statement.
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.
AVA automatically removes unrelated lines in stack traces, allowing you to find the source of an error much faster, as seen above.
AVA uses Babel 7 so you can use the latest JavaScript syntax in your tests. There is no extra setup required. You don't need to be using Babel in your own project for this to work either.
We aim support all finished syntax proposals, as well as all syntax from ratified JavaScript versions (e.g. ES2017). See our @ava/stage-4
preset for the currently supported proposals.
Please note that we do not add or modify built-ins. For example, if you use Object.entries()
in your tests, they will crash in Node.js 6 which does not implement this method.
You can disable this syntax support, or otherwise customize AVA's Babel pipeline. See our Babel recipe for more details.
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.
Please see the files in the docs
directory:
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.
t.plan()
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.
AVA, not Ava or ava. Pronounced /ˈeɪvə/ ay-və.
It's the Andromeda galaxy.
Concurrency is not parallelism. It enables parallelism.
Mark Wubben | Sindre Sorhus | Vadim Demedes |
FAQs
Node.js test runner that lets you develop with confidence.
The npm package ava receives a total of 141,071 weekly downloads. As such, ava popularity was classified as popular.
We found that ava demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.