Node.js test runner that lets you develop with confidence 🚀
MIT License
Bot releases are hidden (Show)
Published by novemberborn almost 3 years ago
AVA 4 is nearly done! We’re not expecting major breaking changes, so barring any bugs or other surprises this should be it.
As always with pre-releases though you’re best-off installing an exact version:
npm install -D -E ava@next
By default, test files are now run in worker threads! Huge thanks to @dnlup for landing this.
Test files should run a little quicker, since it's easier to spin up a worker thread than a child process. You can use --no-worker-threads
on the command line, or workerThreads: false
in your AVA configuration, to fall back to using child processes.
Shared workers are no longer experimental. This is a powerful feature that loads a program in a worker thread in AVA's main process and then communicate with code running in the test workers. This enables your tests to better utilize shared resources during a test run, as well as providing opportunities to set up these resources before tests start (or clean them up after).
When you use watch mode, shared workers remain loaded across runs.
AVA selects test files based on your package.json
or ava.config.*
configuration files. When used on the CLI you can then provide patterns to select a subset of these files.
You can now pass a folder and AVA will select the test files contained therein. Or you can provide a specific JavaScript file and AVA will run it even if it wasn’t selected by your configuration.
If AVA finds files based on the configuration, but none of those were selected to the CLI arguments, it now prints a warning.
AVA now looks for ava.config.*
files in parent directories, until it finds a directory with a .git
directory (or file). This lets you specify AVA configuration at the top of your monorepo and still run AVA from within each package.
@ninevra has worked tirelessly on landing a new snapshot format. It contains all information necessary to regenerate the report file. This allows for snapshots to be updated even if tests or assertions are skipped.
AVA now records which test files failed in the previous run. It then prioritizes testing these files when you run AVA again. Thanks @bunysae!
AVA 4 comes with full ES module support. Both ESM and CJS entrypoints are provided so that you can use it no matter how you manage your project.
The ava.config.js
file is now treated as CJS or ESM depending on module type configured in the package.json
file. ava.config.mjs
is now supported.
If you use JavaScript files with non-standard extensions you can configure AVA to import them.
Note that dependency tracking in watch mode does not yet work with ES modules.
test.macro()
returns an object that can be used with
test()
and hooks. The t.context
type is inherited from test
. When used with TypeScript this gives much better type inference.
Like with AVA 3, regular functions that also have a title
property
that is a string-returning function are supported. However the type checking won’t be as good.
AVA now uses the source map support that’s built in to Node.js itself. This should give better stack traces. However we’re not sure yet what happens if you load a program that automatically modifies stack traces.
Line number selection (where npx ava test.js:5
runs the test at line 5) now uses source maps and so should work better with TypeScript files.
Most assertions now return a boolean indicating whether they passed. If you use AVA with TypeScript, you can use this as a type guard. Thanks @jmarkham828!
(This is not supported for t.snapshot()
and the "throws" assertions.)
AVA 4 requires at least Node.js 12.22, 14.17, 16.4 or 17. Node.js 10 is no longer supported.
If installed globally, AVA will no longer use any locally installed version. Install locally and run with npx ava
instead. When running test files from another project that also has AVA installed, those test files will now fail to run (because they'll try and use that other AVA version).
@ava/babel
has been removed. We haven’t seen enough contributions to that package to recommend it for AVA 4. We’d be open to reinstating it in the future (just as we’d be open to support any other compilation provider).avajs/[email protected]
or newer.esm
package has been removed.ava.config.js
now follows the module type configured in package.json
.ava.config.*
files may be found that are outside your project directory.test.meta.file
and test.meta.snapshotDirectory
are now file URL strings.test()
and t.try()
no longer take an array of test implementations. Use a loop instead.t.throws()
and t.throwAsync()
assertions can no longer be called with a null
value for the expectations argument.test.cb()
and t.end()
have been removed. Use async functions and util.promisify()
instead.t.teardown()
now executes in last-in-first-out order.npx ava -u
to rebuild your snapshots after upgrading.t.snapshot()
no longer works in hooks.t.snapshot()
no longer takes an options argument allowing you to customize the snapshot ID.instanceOf
expectation of t.throws()
and t.throwsAsync()
assertions must now be an Error
constructor.test.macro()
when declaring macros.unknown
.Meta
replaces MetaInterface
, other types with Interface
suffixes now use the Fn
suffix. There may be some other changes too. 4b4b2f63f184056b4038dfc692f99421038d3ec1t.throws()
and t.throwsAsync()
return undefined
when the assertion fails. The type definition now matches this behavior.--config
argument may now point to a file that is not alongside the package.json
file.t.timeout()
, AVA itself won’t time out until your test does. Thanks @OhYash!.test
and .spec
extensions from file names, as well as test-
prefixes.Full changelog since Alpha 2: https://github.com/avajs/ava/compare/v4.0.0-alpha.2...v4.0.0-rc.1
Published by novemberborn over 3 years ago
This is the second (pre)release of AVA 4 🎊 Please read the release notes for Alpha 1.
npx ava
instead 1ee1e826https://github.com/avajs/ava/compare/v4.0.0-alpha.1...v4.0.0-alpha.2
Published by novemberborn over 3 years ago
This is the first (pre)release of AVA 4 🎊 There's some great new features, some cleanup of old interfaces, and some other smaller-but-still-breaking changes.
You can install the latest AVA 4 prerelease using:
npm install -D -E ava@next
By default, test files are now run in worker threads! Huge thanks to @dnlup for landing this. 0e5cc7dc2b1512d0abe9bfba57b26888eedea0cf
Test files should run a little quicker, since it's easier to spin up a worker thread than a child process. You can use --no-worker-threads
on the command line, or workerThreads: false
in your AVA configuration, to fall back to using child processes.
@ninevra has worked tirelessly on landing a new snapshot format. It contains all information necessary to regenerate the report file. This allows for snapshots to be updated even if tests or assertions are skipped. 14ec281dd6d71d46cf2b755e7451262dab6cbc64
AVA's configuration files may now export promises or asynchronous factory methods. The ava.config.js
file is now treated as CJS or ESM depending on module type configured in the package.json
file. ava.config.mjs
is now supported. f7cb1c7b038eba017bd77fc93d9921b1db962174 c7b782098dbaeaacfd671c12ffc5100bfb7be75d
AVA now records which test files failed in the previous run. It then prioritizes testing these files when you run AVA again. Thanks @bunysae! d7426720ad55ba387d86aaae3a3af06a8020c761
Most assertions now return a boolean indicating whether they passed. If you use AVA with TypeScript, you can use this as a type guard. Thanks @jmarkham828! 72a4e2fd4c931b13354ad9d10149c383b4ca48b3 5eea60836402ff0ca052cf1d017deabdf8a6fb36
(This is not supported for t.snapshot()
and the "throws" assertions.)
ava.config.js
now follows the module type configured in package.json
f7cb1c7b038eba017bd77fc93d9921b1db962174 c7b782098dbaeaacfd671c12ffc5100bfb7be75dnpx ava -u
to rebuild your snapshots after upgrading 14ec281dd6d71d46cf2b755e7451262dab6cbc64t.snapshot()
no longer works in hooks bcb750c1551cca380a0003ebc8f66987a6b16d6ct.snapshot()
no longer takes an options argument allowing you to customize the snapshot ID d8b1e89e6e8b88e1582cf02f4cf088c87c2e058ftest.cb()
and t.end()
have been removed. Use async functions and util.promisify()
instead.t.throws()
and t.throwAsync()
assertions can no longer be called with a null
value for the expectations argument 7f64f5c834e8fab29f4778705ee05b2a81867879t.teardown()
now executes in last-in-first-out order dc4483f440fe8736ff71226fd8b18c0e2cc86f51esm
package has been removed 2011b92b638df42b4d050a19e9b37cbb19659970Our TypeScript recipe has been updated with ts-node
and ESM instructions. Thanks @mesqueeb! a0791529c18394d92224232cf9d1696426ada505
We'd also like to thank @kiancross, @papb and @JerryGreen.
https://github.com/avajs/ava/compare/v3.15.0...v4.0.0-alpha.1
Published by novemberborn almost 4 years ago
When you stop using snapshots in a test file, the next time you run ava --update-snapshots
we'll remove the left-over snapshot files. Thanks @ninevra! 4f093ab
@tymfear has been on a roll improving our TAP reporter. t.log()
output is now compliant with the spec 99ab93a. Tests that did not run due to timeouts are now reported 98595dae58209a9062d0238c7a3dd7078a9962d1.
AVA 4 will add full support for ESM configuration files as well as allowing you to have asynchronous factory functions a2f2614cc1e34fb9a7aa204b37b3b25559f203d9. If you're using Node.js 12 or later you can opt-in to these features in AVA 3 by enabling the nextGenConfig
experiment. Say in an ava.config.mjs
file:
export default {
nonSemVerExperiments: {
nextGenConfig: true
},
files: ['unit-tests/**/*]
};
This also allows you to pass an .mjs
file using the --config
argument.
With this experiment enabled, AVA will no longer have special treatment for ava.config.js
files. Instead AVA follows Node.js' behavior, so if you've set "type": "module"
you must use ESM, and otherwise you must use CommonJS.
You mustn't have an ava.config.mjs
file next to an ava.config.js
or ava.config.cjs
file.
See https://github.com/avajs/ava/compare/v3.14.0...v3.15.0 for all changes.
Published by novemberborn almost 4 years ago
With this release, snapshot files are now ordered based on test declaration, not completion. This makes it easier to compare the human-readable reports to your test file, and also stops the .snap
from changing when the reports themselves don't. You'll want to rebuild snapshots after upgrading to this release to isolate any changes. Thanks @ninevra! e66b54ce61d8bb16bbcd15b7fb90893d02e5a65c
We’ve been working on making AVA more extensible. One major step on this path is our new shared worker support: run code in the main process, communicate with test workers and influence execution. Find out more in our shared workers recipe.
See https://github.com/avajs/ava/compare/v3.13.0...v3.14.0 for all changes.
Published by novemberborn about 4 years ago
t.passed
can now be used in tests and teardown functions. Thanks @tymfear! 900dc6d46a1f8728dddfab1e42caef1fa8a51c85null
as the expectation for t.throws()
& t.throwsAsync()
. You can opt in to this early by enabling the disableNullExpectations
experiment. Thanks @JSimoni42! f328a6933af7aca221b08f694bb14b03701eca68See https://github.com/avajs/ava/compare/v3.12.1...v3.13.0 for all changes.
Published by novemberborn about 4 years ago
Normally, AVA loads all files as CommonJS, except for mjs
files and if you've configured "type": "module"
in your package.json
.
As an experiment, you can now configure how AVA loads other file extensions. This is useful if you want to use Node.js' experimental loaders feature. Read more in our documentation. Thank you @macarie for working on this! 5c9dbb96ad0beb7521e5051390478493250ba6b0
There was a bug in our comparison library which meant that negative-index properties on lists were not compared. This was fixed in a patch release, which will definitely be installed when you install AVA 3.12. Your tests may have been passing, even though they should have been failing. They'll fail now. Snapshots may also be different, causing tests to fail.
See https://github.com/avajs/ava/compare/v3.11.1...v3.12.1 for all changes.
Thank you @AnthumChris for making sure our ESM example used ESM syntax (20bc7810536b3b968db5461ff4093bb5ae912050).
Published by novemberborn about 4 years ago
This release fixes corrupted output of the default reporter when test or program code writes to standard out. 5ddc9fda100205a5ca315a86e27a01be443b88b1
Also, thanks to @jonathansamines we've taken another step to using AVA to test AVA. 1150991ba1921cbf888438d46350894484356078
See https://github.com/avajs/ava/compare/v3.11.0...v3.11.1 for all changes.
Published by novemberborn about 4 years ago
t.like()
assertionThanks to @futpib we now have a t.like()
assertion 19c4f35fbae740268dedeeb4d450f813f2d5e85e:
In the following example, the map
property of value
must be deeply equal to that of selector
. However nested.qux
is ignored, because it's not in selector
.
t.like({
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
qux: 'quux'
}
}, {
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
}
})
Read more in the t.like()
assertion documentation.
This assertion was previously introduced as an experiment.
You can now debug tests using the new JavaScript Debug Terminal in VSCode 1.47. We've updated our debugging recipe accordingly. Thank you @connor4312 for the documentation updates and your work on VSCode! bc39bcc3ff92cb2979564ec2e69dc72be6509f78
See https://github.com/avajs/ava/compare/v3.10.1...v3.11.0 for all changes.
Published by novemberborn over 4 years ago
When executing a subset of tests, through --match
or or .only()
or .skip()
, you can no longer also update snapshots. This prevents you from accidentally deleting snapshots. Thank you @bunysae for putting this together. f72fab40160a413f4d7ab0208979fe3e721198ea
If you are skipping a test that you can't immediately fix, but you still need to update snapshots, use .failing()
instead.
t.timeout()
callsThanks to @jonathansamines you can now provide a message string when using t.timeout()
. This can be useful if your test depends on some other setup that may not have been completed: ca8ea45587ebefa5584d6a7aa50adf90840701cf
test('foo', t => {
t.timeout(100, 'make sure database has started');
// Write your assertions here
});
t.try()
does not work in hookst.try()
has never worked in hooks, but thanks to @okyantoro it now fails properly instead of crashing. d01db61ee5e9785d9f80ad5683cac21db4b96509
t.snapshot()
does not really work in hooks eithert.snapshot()
sort of works in hooks, but we'll be removing this in AVA 4. You can opt in to this behavior by enabling the disableSnapshotsInHooks
experiment. Again thank you @okyantoro d01db61ee5e9785d9f80ad5683cac21db4b96509.
t.like()
The experimental t.like()
assertion should now work better with TypeScript.
See https://github.com/avajs/ava/compare/v3.9.0...v3.10.1 for all changes.
Published by novemberborn over 4 years ago
Thanks to @futpib we now have an experimental t.like()
assertion 19c4f35fbae740268dedeeb4d450f813f2d5e85e:
In the following example, the map
property of value
must be deeply equal to that of selector
. However nested.qux
is ignored, because it's not in selector
.
t.like({
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
qux: 'quux'
}
}, {
map: new Map([['foo', 'bar']]),
nested: {
baz: 'thud',
}
})
Read more in the t.like()
assertion documentation and let us know what you think.
@yjpa7145 has contributed an experiment to reverse the order in which t.teardown()
functions are run, so that the last registered function is called first 952a0177758c5601a72c2b050fc0308e7fa774c7. This will be the behavior in AVA 4.
To enable both these experiments update your AVA configuration:
package.json
:
{
"ava": {
"nonSemVerExperiments": {
"likeAssertion": true,
"reverseTeardowns": true
}
}
}
ava.config.js
:
export default {
nonSemVerExperiments: {
likeAssertion: true,
reverseTeardowns: true
}
}
@Michael55555 has helped us combine our reporter code into a single file b3866b6b06c98862a19f6cb27ec28b643e2f00c7. We've also made some other tweaks and improvements baaf99a792eed586678a0cf88864f3f0aa16bd7a. Let us know if anything seems amiss.
@bunysae made it so that missing or extraneous objects in diffs are printed with extra depth https://github.com/concordancejs/concordance/pull/62.
Node.js 13 has reached end-of-life. Per our support statement we have removed it from our test matrix and supported version list.
See https://github.com/avajs/ava/compare/v3.8.2...v3.9.0 for all changes. Thank you @paulrobertlloyd and @Autre31415 for contributing documentation improvements.
Published by novemberborn over 4 years ago
Published by novemberborn over 4 years ago
Great news, this is a feature heavy release!
First off, though, AVA now officially supports Node.js 14. Thank you @zackschuster! 2e7c76b85cb65a04605fed843ee2f571afc66c37
AVA can now run tests at specific line numbers! 🎉
Given the following test file:
test.js
1: test('unicorn', t => {
2: t.pass();
3: });
4:
5: test('rainbow', t => {
6: t.fail();
7: });
Running npx ava test.js:2
for would run the unicorn
test. In fact you could use any line number between 1
and 3
.
This feature is only available from the command line. It won't work if you use tools like ts-node/register
or @babel/register
, and it does not currently work with @ava/babel
and @ava/typescript
. See https://github.com/avajs/ava/issues/2473.
Thank you @ulken for your hard work and patience to get this shipped. 1222ce9538e4890c20af695e558e3ee490f5a41b
Sometimes tests have side-effects you want to clean up. @ulken has implemented t.teardown()
which lets you register teardown functions within your test. They'll run once your test has finished, even if it failed: 75cbc3b2a53d3b8530266b10bed71b838bc11fec
test('read file', t => {
fs.writeFileSync('file.txt', '👋');
t.teardown(() => fs.unlinkSync('file.txt');
// Run assertions
});
Thanks to @bunysae, stack traces now include Node.js internals. Previously we removed them because we wanted you to focus on your own code, but quite often they do provide context. Now they're displayed, but somewhat dimmed. 9a9351ddbee9c6c76601210c5dd8f5b0d81cc3b0
Watch mode with the default reporter once again accepts key input. Thanks @pcdevil! 59c227d9c5261117d99e8e84693b9c89c3438a92
afterEach()
and afterEach.always()
hooks can now determine whether the test passed. Thank you @bunysae for contributing this! 8f312c0
test('passes', t => t.pass());
test.afterEach(t => {
if (t.passed) {
// Do something because the test passed
} else {
// Do something because the test failed
}
});
If you've ever wanted to save some files along with AVA's snapshots, you can now determine the directory path by accessing test.meta.snapshotDirectory
. Thank you @ulken! cb5f9f7
See https://github.com/avajs/ava/compare/v3.7.1...v3.8.1 for all changes.
Published by novemberborn over 4 years ago
Published by novemberborn over 4 years ago
If you've ever wanted to save some files along with AVA's snapshots, you can now determine the directory path by accessing test.meta.snapshotDirectory
. Thank you @ulken ! cb5f9f70879ee549837c31e577e01f87970164ed
See https://github.com/avajs/ava/compare/v3.6.0...v3.7.0 for all changes.
Published by novemberborn over 4 years ago
afterEach()
and afterEach.always()
hooks can now determine whether the test passed. Thank you @bunysae for contributing this! 8f312c0f2c978ba39baae0f701015d79af18cbde:
test('passes', t => t.pass());
test.afterEach(t => {
if (t.passed) {
// Do something because the test passed
} else {
// Do something because the test failed
}
});
@mbiesiad has diligently translated our documentation to Polish. Thank you @kekuu for reviewing.
Also thank you @timgates42 for fixing a typo in our documentation. ede4f322b4fa6263c8ae14ec04282ab06bb0afd4
See https://github.com/avajs/ava/compare/v3.5.0...v3.6.0 for all changes.
Published by novemberborn over 4 years ago
When using ava debug
, you can now specify the address or hostname the inspector is available through by using the --host
option. Thanks to @DYefimov for contributing this! 13d66519
See https://github.com/avajs/ava/compare/v3.4.0...v3.5.0 for all changes. Spoiler alert: it's just this one 😉
Published by novemberborn over 4 years ago
t.try()
assertionThe new t.try()
allows you to try assertions without causing the test to fail:
test('do the thing', async t => {
const attempt = () => t.try(async tt => {
const result = await getResult()
// getResult() can be flaky and sometimes throws :(
tt.is(result, 'expected')
})
const firstAttempt = await attempt()
if (firstAttempt.passed) return firstAttempt.commit()
t.log('Retrying (just once)')
firstAttempt.discard()
const secondAttempt = await attempt()
secondAttempt.commit()
})
You can use any test implementation with t.try()
, including (arrays of) macros. You can decide what to do with attempts. You can even run attempts concurrently, so long as they don't use snapshot assertions.
This is great building block for handling all kinds of advanced test scenarios. We can't wait to see what you'll do with it! Find out more in the assertion documentation.
This feature was previously behind an experimental flag. That flag has now been removed. If you have enabled the flag you'll have to update your AVA config. Also note that as of this release, attempt titles are always prefixed with the title of the parent test 7ee3a0e5940a105dec447851c777ea44555e8220.
Once again, thank you @qlonik for contributing this new assertion.
As of the 3.3.0 release, AVA can load ESM test files! Check our updated ES Modules recipe for details.
Our ESM support is still incomplete. Progress is tracked in the ESM support project. Join us, won't you?
t.throws()
and t.throwsAsync()
assertions can now be called with undefined
as the second argument. Previously, if you wanted to set an assertion message but did not want to provide any expectations for the thrown error you had to pass null
. That's still allowed, of course. d0e21612390d50f084f7062b051164624ef391ff @stavalfiava.config.js
files once again work with our @ava/typescript
package f4d4edd3379e51ac733b184e20dd0228be24245a@types/node
7a1dacf369a5857309effa42fc1638d7b8fe4eadtest.cb()
is used with asynchronous functions or observables f5a8c2b2df757886247492ce3372f1e18da36ab7 @toddkcarlsonjsdom-global
instead of browser-env
3f9c616b44c7374404d75af63f393750160c6b84 @ScrumSee https://github.com/avajs/ava/compare/v3.3.0...v3.4.0 for all changes.
Published by novemberborn over 4 years ago
AVA can now load ESM test files! 🎉Thank you @arlac77 for making this happen. Check our updated ES Modules recipe for details.
Our ESM support is still incomplete. Progress is tracked in the ESM support project. Join us, won't you?
See https://github.com/avajs/ava/compare/v3.2.0...v3.3.0 for all changes.
Published by novemberborn over 4 years ago
This release improves the integration with the new @ava/typescript
package, which allows AVA to load pre-compiled TypeScript files.
First, install the new @ava/typescript
package:
npm install --save-dev @ava/typescript@^1.1
Now let's assume your TypeScript files are in a src
directory, output to a build
directory. Configure AVA like so:
ava.config.js
file:
export default {
typescript: {
rewritePaths: {
'src/': 'build/'
}
}
}
Compile your TypeScript files and run your tests! Or, to run a specific test file, run npx ava src/test.ts
.
For more examples see the @ava/typescript
package.
As exciting as this is, it's still early days. We need your help improving our TypeScript support. Check out the open issues.
See https://github.com/avajs/ava/compare/v3.1.0...v3.2.0 for all changes.