Back in January we started work on the 1.0 release, taking the opportunity to upgrade to Babel 7 and follow its beta releases. It’s been a year where we made massive improvements to AVA. It’s also been a year with many exciting events in our personal lives. Be it honeymoons & weddings, work & friends, naturalizations and international relocations.

So, we’re done. Or, rather, we’re just beginning. Testing can be a drag. AVA helps you get it done. Its concise API, detailed error output, embrace of new language features and process isolation let you write tests more effectively. So you can ship more awesome code or do non-programming things.

Starting now we’ll push out patches and new features more regularly. And, when the time comes, ship a 2.0 and a 3.0 and so forth. If you like what we’re doing, why not try and contribute? We’re a friendly bunch and we could use your help to make AVA even better.

We couldn’t have gotten here without the nearly one hundred people who’ve contributed more, and the many more who suggested improvements, reported bugs and provided feedback. And, of course, everyone who’s used AVA. Thank you for your enthusiasm and support.

Install AVA 1.0 today using npm init ava or find us on GitHub.

Mark & Sindre

What’s new & improved

Assertions

New t.throws() behavior & t.throwsAsync()

We’ve rewritten t.throws() so it behaves better, has better error output and lets you write better tests:

The assertion takes a first thrower argument. It must throw an exception, or your test fails. Throwing other values like strings also causes your test to fail.

The exception must be an error object.

The assertion returns the exception.

You have a few ways of asserting that the exception is as designed. You can pass a second argument:

If you pass a function it should be a constructor: the exception must be an instance of it. Previously you could pass a validation function. This is no longer possible.

If you pass a string: the exception’s message should be equal to it.

should be equal to it. If you pass a regular expression: the exception’s message should match it.

The most exciting new feature though is that you can pass an expectation object. A combination of the following expectations is supported:

This makes tests like these much easier to write:

We’ve removed promise support from t.throws() and t.notThrows() . Use the new t.throwsAsync() and t.notThrowsAsync() assertions instead. Support for observables has been removed completely.

The original behavior was both hard to explain and hard to express in Flow and TypeScript. Now, if you have a function that throws a synchronous error, use t.throws() (or t.notThrows() ). If you have a promise that should reject, or an asynchronous function that should fail, use await t.throwsAsync() (or await t.notThrowsAsync() ).

Generally speaking, you should be able to replace every occurrence of await t.throws with await t.throwsAsync , and await t.notThrows with await t.notThrowsAsync . A transform file for jscodeshift is available in this Gist. Run it like:

Change test.js to a glob pattern that matches your test files. See the jscodeshift CLI usage documentation for further details.

Bound assertion methods

Assertion methods are now bound to the test, meaning you can provide them as direct arguments to other functions. A contrived example:

Whilst not strictly assertions, t.plan() and t.log() are now also bound to the test.

BigInt

As part of our Node.js 10 support, you can now use BigInt values in t.deepEqual() and t.snapshot() . Note that this is still a stage-3 proposal.

Babel 7

AVA now uses Babel 7, with support for babel.config.js files. We'll automatically use your project's Babel configuration. Babel options must now be specified in a testOptions object. This will allow us to add source related options in the future.

Our @ava/stage-4 preset is now accessible via ava/stage-4 . We've added transforms for the latest ES2018 features where available (and even an ES2019 one!). You can also disable ava/stage-4 entirely:

package.json :

Or, you can disable just ES module compilation:

package.json :

The powerAssert option and command line flags have been removed. You can now disable AVA's test enhancements by setting compileEnhancements to false . You can also disable AVA's Babel pipeline entirely:

package.json :

Serial hooks and context

Hooks declared using test.serial will now execute serially. Only one of those hooks will run at a time. Other hooks run concurrently. Hooks still run in their declaration order.

Note that concurrent tests run concurrently. This means that .beforeEach() and .afterEach() hooks for those tests may also run concurrently, even if you use test.serial to declare them.

t.context can now be used in .before and .after hooks.

CLI

Pass flags to your test

AVA now forwards arguments, provided after an -- argument terminator, to the worker processes. Arguments are available from process.argv[2] onwards.

There’s a new recipe on how to use this.

Previously AVA populated process.argv[2] and process.argv[3] with some undocumented internal values. These are no longer available.

Resetting AVA’s cache

The --no-cache CLI flag has been replaced by a --reset-cache command. The latter resets AVA's regular cache location. You can still disable the cache through the cache configuration option.

Configuration

Introducing ava.config.js

You can now configure AVA through an ava.config.js file. It must be placed next to the package.json , and you mustn't have any "ava" options in the package.json file. Export the configuration as a default:

Or export a factory function:

Following our convention to use ES modules in test files, we’re expecting ES modules to be used in the configuration file. If this is causing difficulties please let us know in https://github.com/avajs/ava/issues/1820.

Configurable test & helper file extensions

You can now tell AVA to run test files with extensions other than js ! For files that should be compiled using Babel you can specify babel.extensions :

package.json :

Or define generic extensions, e.g. for use with TypeScript:

package.json :

Note that AVA still assumes test & helper files to be valid JavaScript. They’re still precompiled to enable some AVA-specific enhancements. You can disable this behavior by specifying "compileEnhancements": false .

Snapshots

Adding new snapshots no longer causes the Markdown files to become malformed. Snapshots are now consistent across operating systems. If you’ve previously generated snapshots on Windows, you should update them using this release.

We now support BigInt and <React.Fragment> in t.snapshot() . We've also improved support for the Symbol.asyncIterator well-known symbol. Unfortunately, these changes are not backward compatible. You'll need to update your snapshots when upgrading to this release.

We’ve improved how AVA builds snapshot files to better support precompiled projects. Say, if you compile your TypeScript test files using tsc before running AVA on the build output. AVA will now use the source map to figure out the original filename and use that as the basis for the snapshot files. You'll have to manually remove snapshots generated by previous AVA versions.

Type definitions

The TypeScript and Flow definitions have been rewritten and much improved. The TypeScript recipe has been updated to reflect the changes, and there’s a new Flow recipe too.

TypeScript

AVA recognizes TypeScript build errors when using ts-node/register .

TypeScript now type-checks additional arguments used by macros. You must type the arguments used:

Other improvements

You can now specify helpers — that need to be compiled by AVA — in the require configuration.

configuration. --fail-fast behavior has been improved. AVA now makes sure not to start new tests. Tests that are already running though will finish. Hooks will also be called. AVA now prints the number of skipped test files if an error occurs and --fail-fast is enabled.

behavior has been improved. AVA now makes sure not to start new tests. Tests that are already running though will finish. Hooks will also be called. AVA now prints the number of skipped test files if an error occurs and is enabled. AVA now uses its own Chalk instance, so AVA’s color settings no longer impact the code you’re testing.

Error serialization has been made smarter, especially if non-Error errors are encountered.

Uncaught exceptions and unhandled rejections are now shown with a code excerpt.

You should see fewer repeated test timeout messages.

Error messages now link to the documentation appropriate for the version of AVA you’re using.

AVA now 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.

package for a list of supported CI environments. AVA now detects when it’s required from a Node.js REPL.

We’ve improved the colors for use on light terminal themes.

The assert module in Node.js 10 no longer crashes.

module in Node.js 10 no longer crashes. Source maps, generated by AVA when compiling test & helper files, now contain correct paths to the source files.

TTY support for process.stderr is now emulated in the worker processes.

is now emulated in the worker processes. The default reporter now includes files that did not declare any tests in its final output.

AVA now prints pending tests when timeouts occur, when using --verbose .

. <React.Fragment> can be used in t.deepEqual .

can be used in . title functions of macros now receive undefined rather than an empty string if no title was given in the test declaration. This means you can use default parameters.

Breaking changes since 0.25.0

Supported Node.js versions

We’ve published a statement with regards to which Node.js versions we intend to support. As of this release, we’re only supporting Node.js 6.12.3 or newer, 8.9.4 or newer, 10.0.0 or newer and 11.0.0 or newer. This does not include Node.js 7 and 9.

Tests must now have titles, and they must be unique

You can no longer do:

Instead, all tests must have titles, and they must be unique within the test file:

This makes it easier to pinpoint test failures and makes snapshots better too.

Note that AVA no longer infers a test title from a function name:

Modifier chaining

AVA’s various test modifiers ( .serial , .skip ) must now be used in the correct order:

.serial must be used at the beginning, e.g. test.serial() .

must be used at the beginning, e.g. . .only and .skip must be used at the end, e.g. test.skip() . You cannot combine them.

and must be used at the end, e.g. . You cannot combine them. .failing must be used at the end, but can be followed by .only and .skip , e.g. test.cb.failing() and test.cb.failing.only() .

must be used at the end, but can be followed by and , e.g. and . .always can only be used after .after and .afterEach , e.g. test.after.always() .

can only be used after and , e.g. . .todo() is only available on test and test.serial . No further modifiers can be applied.

Declaring tests

You must declare all tests and hooks at once. This was always the intent but previously AVA didn’t enforce it very well. Now, once you declare a test or hook, all other tests and hooks must be declared synchronously. However, you can perform some asynchronous actions before declaring your tests and hooks.

test export

We’re no longer exporting the test() method as a named export. Where before you could use import {test} from 'ava' , you should now write import test from 'ava' .

Set default title using parameters syntax

Macros can generate a test title. Previously, AVA would call the title function with an empty string if no title was given in the test declaration. Now, it'll pass undefined instead. This means you can use default parameters. Here's an example:

This is a breaking change if you were concatenating the provided title, under the assumption that it was an empty string.

Assertions

t.throws() & t.notThrows()

Thrown exceptions (or rejection reasons) must now be error objects.

t.throws() and t.notThrows() no longer support observables or promises. For the latter, use await t.throwsAsync() and await t.notThrowsAsync() instead.

Generally speaking, you should be able to replace every occurence of await t.throws with await t.throwsAsync , and await t.notThrows with await t.notThrowsAsync . A transform file for jscodeshift is available in this Gist. Run it like:

Change test.js to a glob pattern that matches your test files. See the jscodeshift CLI usage documentation for further details.

Skipping assertions

Assertions can be skipped by using .skip at the end of the assertion, e.g. t.deepEqual.skip() . You can now safely skip snapshot tests, though not whilst updating snapshots.

t.ifError()

We’ve removed the t.ifError() assertion. It worked the same as t.falsy() , so if you were using it please switch to t.falsy() instead.

Configuration changes

The source option has been renamed to sources . This is now consistent with files . AVA will exit with an error if it encounters the source option.

We’ve also removed unintentional support for init , watch and updateSnapshot options.

Babel

The "default" and "inherit" configuration values have been removed. Babel options must now be specified in a testOptions object. This will allow us to add source related options in the future.

The powerAssert option and command line flags have been removed. You can now disable AVA's test enhancements by setting compileEnhancements to false .

The Babel recipe has been updated with the latest details.

Updated type definitions

The TypeScript and Flow definitions have been rewritten. The definitions export different interfaces so you may need to update your test code as well.

TypeScript now type-checks additional arguments used by macros. You must type the arguments used.

Internals

Some other internals have changed. You shouldn’t have been relying on these, though if you did we’re interested in hearing about it so we can better support your use case.

The private t._test value has been removed

value has been removed Some of the communication between the main process and the test workers has changed

Access to the options object from inside a worker process has changed

Other potential breaking changes

We’ve removed support for @std/esm , in favor of the plain esm package.

, in favor of the plain package. The ava/stage-4 preset is applied after all other plugins and presets.

preset is applied after all other plugins and presets. Test implementations are now called with null as the this value.

as the value. All reporters write to stdout . The stdout and stderr output from workers is written to process.stderr . AVA will insert linebreaks in process.stdout after writing a chunk to process.stderr that does not end in a line break.

. The and output from workers is written to . AVA will insert linebreaks in after writing a chunk to that does not end in a line break. The --no-cache CLI flag has been replaced by a --reset-cache command. The latter resets AVA's regular cache location. You can still disable the cache through the cache configuration option.

CLI flag has been replaced by a command. The latter resets AVA's regular cache location. You can still disable the cache through the configuration option. We’ve dropped support for using generator functions as test implementations. This was a remnant of the dark days before async / await support.

/ support. Snapshots need to be regenerated.

If you pre-compile your test files, the snapshot files may be created at new file paths. You’ll have to manually remove any old files.

New recipes

There’s a new recipe on using ES modules. We’ve also added a recipe on setting up tests and how test webapps using AVA and Puppeteer.

All changes 📚

v0.25.0...v1.0.0

Thanks 💌

💖 Huge thanks to @okyantoro, @JasonRitchie, @forresst, @mdvorscak, @kugtong33, @motss, @BusbyActual, @billyjanitsch, @Briantmorr, John-David Dalton, @malimichael, @martypdx, @clemtrek, @samuelli, @emilyschultz, @hallettj, @isnifer, @Jaden-Giordano, @good-idea, Jamie Kyle, @tobil, @TheDancingCode, @btkostner, @CanRau, @coreyfarrell, @ivanschwarz, @jagoda, @padmaia, @ronen, @sh7dm, @sharkykh, @Phrynobatrachus, @grant37, @xxczaki, @robertbernardbrown, @lo1tuma, @goooseman, @wmik, @vancouverwill, @qlonik, @vlajos and @itskolli for helping us with this release. We couldn’t have done it without you!

Get involved ✌️

We welcome new contributors. AVA is a friendly place to get started in open source. We have a great article on getting started contributing and a comprehensive contributing guide.