Node.js test runner that lets you develop with confidence 🚀
MIT License
Bot releases are hidden (Show)
Published by novemberborn over 4 years ago
AVA can now load pre-compiled TypeScript files!
First, install the new @ava/typescript
package:
npm install --save-dev @ava/typescript
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.
Thanks to @jhechtf for fixing our TypeScript recipe after the changes in AVA 3.0 91a00864f7f113dd63a2c4ecc383fc8c45f79665
See https://github.com/avajs/ava/compare/v3.0.0...v3.1.0 for all changes.
Published by novemberborn over 4 years ago
When we began AVA, JavaScript was very different. Most syntax you find familiar today was not supported by Node.js. Instead we relied on Babel to support that syntax before it made its way to Node.js itself.
These days most new stage-4 syntax is adopted quickly. It's often not necessary to transpile anything. Therefore we're removing our built-in Babel support from AVA itself.
Without Babel you'll have to resort to using require()
functions in your JavaScript files. But, you say, Node.js 13 supports ECMAScript Modules!
Well, we're getting there. For a start, AVA now also looks for .cjs
files. And .mjs
files are recognized too, but can't be loaded just yet. This also impacts ava.config.js
files. If you'd like to help out delivering full .mjs
support check out the issues in the ESM support project.
Removing Babel allowed us to simplify how test files are selected. Likely non-test files, inside "fixture" or "helper" directories are ignored. The same for files that are inside an underscore-prefixed directory. We've made some other breaking changes in this area so please do read the full release notes.
You can again pass glob patterns on the CLI. However these now filter the test files that AVA already selected based on the configuration. In other words you can't run files that wouldn't be run by invoking npx ava
.
AVA now interrupts your tests if there's no progress for 10 seconds. Use the timeout
configuration or --timeout
CLI option to change this.
You can now debug individual test files using the V8 Inspector:
npx ava debug test.js
Connect to the debugger with Chrome DevTools. Or set up a debugger in VSCode.
You can now configure the arguments passed to Node.js itself when AVA starts its worker processes. Use the nodeArguments
configuration or combine with the --node-arguments
CLI option.
We now support Node.js 10, 12 and 13. The minimal versions are 10.18.0, 12.14.0 and 13.5.0 respectively.
Utilize Babel with AVA by installing our @ava/babel
package and then enabling Babel by setting babel: true
in the AVA configuration. Having this as a separate package means it can evolve independently.
The compileEnhancements
setting has been moved into the babel
configuration. Consequently, the t.assert()
assertion will only print its detailed information when you use Babel. And we won't be able to catch typical mistakes with t.throws()
as well as we could before.
The ava/stage-4
preset is now available from @ava/babel/stage-4
. Our old @ava/babel-preset-transform-test-files
and @ava/babel-preset-stage-4
packages are no longer maintained and not installed with AVA itself.
AVA now also looks for .cjs
and .mjs
test files. That said, .mjs
files cannot be loaded just yet.
Also, when you add "type": "module"
, AVA would really like to treat .js
files as ECMAScript Modules, but can't just yet.
Similarly,ava.config.cjs
configuration files are now supported. ava.config.mjs
files not just yet.
With AVA 2, we loaded ava.config.js
files using the esm
package. To avoid confusion between the different module formats we now only support export default
statements. No import
, no __filename
. Configuration files that have dependencies should be written as a .cjs
file for now.
Configuration files can only have .cjs
, .js
and .mjs
extensions.
The remaining work is tracked in the ESM support project.
When you use the default configuration AVA will no longer select files matching the following glob patterns:
**/__tests__/**/__helper__/**/*
**/__tests__/**/__helpers__/**/*
**/__tests__/**/__fixture__/**/*
**/__tests__/**/__fixtures__/**/*
**/test/**/helper/**/*
**/test/**/helpers/**/*
**/test/**/fixture/**/*
**/test/**/fixtures/**/*
**/tests/**/helper/**/*
**/tests/**/helpers/**/*
**/tests/**/fixture/**/*
**/tests/**/fixtures/**/*
Additionally, when a file has a parent directory that starts with a single underscore, it can never be a test file.
test.js
files are only selected if they're next to the package.json
file, or inside top-level src
and source
directories.
We've removed the configuration of helpers. Previously, files selected by the helpers
glob patterns were never considered test files. Now that this configuration is no longer supported you'll need to ensure the files
patterns exclude your helper files. If you're using Babel, you can configure the compilation of additional files .
The sources
configuration has also been removed. Instead, use the ignoredByWatcher
configuration. Changes to files matched by these glob patterns will not cause the watcher to rerun tests.
Negated sources
patterns must be used without the negation in ignoredByWatcher
:
export default {
- sources: ['!examples/**/*']
+ ignoredByWatcher: ['examples/**/*']
}
Internally we've replaced meow
by yargs
. We're not expecting things to break because of this, but you never know.
The --reset-cache
argument has been replaced by a proper reset-cache
command:
npx ava reset-cache
AVA again accepts glob patterns via the CLI:
npx ava '**/api/**/*'
The way this work is that AVA first finds all test files, according to the configuration, and then filters to select just the files that also match the glob patterns passed via the CLI.
You can still pass paths to specific files:
npx ava src/api/test/my-api-test.js
However unlike with AVA 2, you can no longer specify test files that aren't already selected by AVA's configuration.
t.throws()
and t.throwsAsync()
assertionsThe second argument passed to these assertions must now be an expectation
object. You can no longer pass the expected constructor, error message or regular expression.
esm
versions has been removed.NODE_PATH
environment variable is no longer rewritten to ensure values are absolute paths.subscribe
function is assumed to be an observable. AVA's type definition has been updated accordingly.https://github.com/avajs/ava/compare/v2.4.0...v3.0.0
Thank you @tymfear, @HeathNaylor, @grnch, @alexdrans, @MoppetX, @jimmywarting, @micaelmbagira, @aptester, @theashraf, @sramam and @maximelkin. We couldn't have done this without you!
Published by novemberborn almost 5 years ago
We've been busy building AVA 3. It comes with a fair amount of breaking changes but also some exciting features, like a built-in debug mode!
You can install the latest beta today:
npm install -D -E ava@next
This is the second beta release. It addresses the known issues from the first beta.
Please read the 3.0.0 Beta 1 release notes first
t.assert()
once again counts as a passed assertion--update-snapshots
works againconsole
and process
are available in ava.config.js
fileshttps://github.com/avajs/ava/compare/v3.0.0-beta.1...v3.0.0-beta.2
Thank you @aptester, @theashraf and @sramam. We couldn't have done this without you!
Published by novemberborn almost 5 years ago
We've been busy building AVA 3. This is the first beta release. It comes with a fair amount of breaking changes but also some exciting features, like a built-in debug mode!
That said there are some known issues:
t.assert()
does not count as a passed assertionava.config.js
You can install the latest beta today:
npm install -D -E ava@next
When we began AVA, JavaScript was very different. Most syntax you find familiar today was not supported by Node.js. Instead we relied on Babel to support that syntax before it made its way to Node.js itself.
These days most new stage-4 syntax is adopted quickly. It's often not necessary to transpile anything. Therefore we're removing our built-in Babel support.
Instead you can utilize Babel with AVA by installing our @ava/babel
package and then enabling Babel by setting babel: true
in the AVA configuration. Having this as a separate package means it can evolve independently.
The compileEnhancements
setting has been moved into the babel
configuration. Consequently, the t.assert()
assertion will only print its detailed information when you use Babel. And we won't be able to catch typical mistakes with t.throws()
as well as we could before.
The ava/stage-4
preset is now available from @ava/babel/stage-4
. Our old @ava/babel-preset-transform-test-files
and @ava/babel-preset-stage-4
packages are no longer maintained and not installed with AVA itself.
Without Babel you'll have to resort to using require()
functions in your JavaScript files. But, you say, Node.js 13 supports ECMAScript Modules!
Well, we're getting there. For a start, AVA now also looks for .cjs
and .mjs
test files. That said, .mjs
files cannot be loaded just yet.
Also, when you add "type": "module"
, AVA would really like to treat .js
files as ECMAScript Modules, but can't just yet.
Similarly,ava.config.cjs
configuration files are now supported. ava.config.mjs
files not just yet.
With AVA 2, we loaded ava.config.js
files using the esm
package. To avoid confusion between the different module formats we now only support export default
statements. No import
, no __filename
. Configuration files that have dependencies should be written as a .cjs
file for now.
Configuration files can only have .cjs
, .js
and .mjs
extensions.
The remaining work is tracked in the ESM support project.
Removing Babel allowed us to simplify how test files are selected. First of all, when you use the default configuration AVA will no longer select files matching the following glob patterns:
**/__tests__/**/__helper__/**/*
**/__tests__/**/__helpers__/**/*
**/__tests__/**/__fixture__/**/*
**/__tests__/**/__fixtures__/**/*
**/test/**/helper/**/*
**/test/**/helpers/**/*
**/test/**/fixture/**/*
**/test/**/fixtures/**/*
**/tests/**/helper/**/*
**/tests/**/helpers/**/*
**/tests/**/fixture/**/*
**/tests/**/fixtures/**/*
Additionally, when a file has a parent directory that starts with a single underscore, it can never be a test file.
test.js
files are only selected if they're next to the package.json
file, or inside top-level src
and source
directories.
We've removed the configuration of helpers. Previously, files selected by the helpers
glob patterns were never considered test files. Now that this configuration is no longer supported you'll need to ensure the files
patterns exclude your helper files. If you're using Babel, you can configure the compilation of additional files .
The sources
configuration has also been removed. Instead, use the ignoredByWatcher
configuration. Changes to files matched by these glob patterns will not cause the watcher to rerun tests.
Negated sources
patterns must be used without the negation in ignoredByWatcher
:
export default {
- sources: ['!examples/**/*']
+ ignoredByWatcher: ['examples/**/*']
}
Internally we've replaced meow
by yargs
. We're not expecting things to break because of this, but you never know.
The --reset-cache
argument has been replaced by a proper reset-cache
command:
npx ava reset-cache
AVA again accepts glob patterns via the CLI:
npx ava '**/api/**/*'
The way this work is that AVA first finds all test files, according to the configuration, and then filters to select just the files that also match the glob patterns passed via the CLI.
You can still pass paths to specific files:
npx ava src/api/test/my-api-test.js
However unlike with AVA 2, you can no longer specify test files that aren't already selected by AVA's configuration.
t.throws()
and t.throwsAsync()
assertionsThe second argument passed to these assertions must now be an expectation
object. You can no longer pass the expected constructor, error message or regular expression.
We now support Node.js 10, 12 and 13. The minimal versions are 10.18.0, 12.14.0 and 13.5.0 respectively.
esm
versions has been removed.NODE_PATH
environment variable is no longer rewritten to ensure values are absolute paths.You can now debug individual test files using the V8 Inspector:
npx ava debug test.js
Connect to the debugger with Chrome DevTools. Or set up a debugger in VSCode.
subscribe
function is assumed to be an observable. AVA's type definition has been updated accordingly.https://github.com/avajs/ava/compare/v2.4.0...v3.0.0-beta.1
Thank you @tymfear, @HeathNaylor, @grnch, @alexdrans, @MoppetX, @jimmywarting and @micaelmbagira. We couldn't have done this without you!
Published by novemberborn about 5 years ago
t.try()
assertionsThanks to the amazing work and patience of @qlonik we're shipping a new assertion! t.try()
lets you perform assertions and decide whether to commit or discard their outcome. All kinds of interesting things can be built on top of this, from fuzzy testers to new test interfaces and more.
We're excited to get this out there, but it's not quite done yet. For now you have to opt in to this new feature. Being opt-in, we may make changes (breaking ones even!) until we feel this is stable.
To opt in, configure AVA with the following:
package.json
:
{
"ava": {
"nonSemVerExperiments": {
"tryAssertion": true
}
}
}
ava.config.js
:
export default {
nonSemVerExperiments: {
tryAssertion: true
}
};
We'd love to hear your feedback. Please join us in this issue: https://github.com/avajs/ava/issues/2250
Also, if you're looking to help out with the remaining issues so that we can ship this without the opt-in, have a look at this project: https://github.com/orgs/avajs/projects/1
Thanks again @qlonik!
Thank you @jeremenichelli, @jamesgeorge007, @dongjae93, @qlonik and @tryzniak. We couldn't have done this without you!
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.
Published by novemberborn about 5 years ago
import-local@^3.0.2
which fixes issues with Lerna projects.t.context
to unknown
, in line with TypeScript's changes in their 3.5 release. 2fc7d56475ca1d77078abc3e08390341bedda58fThank you @MarchWorks, @yovasx2 and @bobthekingofegypt. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
You can now specify an alternative config file, using the --config
CLI argument. This is useful if you want to run unit tests separately from integration tests, since you can have a config file specific to your integration tests which specifies different glob patterns. 2dae2bfaf4b4ae53700fa439f34923b5a2c35a83
We're now faking the new hasColors()
method for better compatibility with Node.js 12. d3997971a42a6c8e5599d16c8c457c792ce943c6
We've removed Node.js 11 from our test matrix. You should upgrade to Node.js 12. 90acbb93ca0d92aeedd2b8101a3692ef3b864dc7
Thank you @langri-sha, @keyspress, @cdaringe and @okyantoro. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
Thank you @anishkny, @yovasx2 and @mihai-dinu. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
Per the Node.js release schedule, the 6.x releases reach end of live on April 30th. Consequently we've removed support in AVA. We are now testing with Node.js 12 though. 3a4afc6cf35aeffb6b019c6b75fa9b8e071bb53d
We've been working on simplifying how test files and helpers are selected. First off, the files
option now only accepts glob patterns. If you configured it with directories before, please add /**/*
to get the previous behavior.
The files
and sources
options must now be arrays containing at least one pattern. It's no longer possible to override a default exclusion pattern, but we're looking at making these configurable separately.
AVA used to treat all files inside a helpers
directory as test helpers. Finding these files could be really slow, however, and it also meant you couldn't have tests inside a helpers
directory. Instead you can now specify glob paterns to find these helpers:
{
"ava": {
"helpers": [
"**/helpers/**/*"
]
}
}
Test files starting with an underscore are still recognized as helpers.
Files inside fixtures
directories are no longer ignored, and will now be treated as test files. The watcher now also watches ava.config.js
files.
AVA now also selects files ending with .spec.js
when looking for tests, as well as looking in tests
directories. 08e99e516e13af75d3ebe70f12194a89b610217c b1e54b1a02ba7220571a06e4d324d460ea7ece54
The CLI now only takes file paths, not glob patterns.
We'd like some help updating our ESLint plugin as well.
When you run tests locally and add a new snapshot, AVA automatically updates the .snap
file. However if you forget to commit this file and then run your CI tests, they won't fail because AVA quietly updates the .snap
file, just like it does locally.
With this release, AVA will fail the t.snapshot()
assertion if it is run in CI and no snapshot could be found. 0804107b49ef3bb43656cd48d27b0d54ea080d71
AVA now enforces assertion messages to be strings. The message is only used when the assertion fails, and non-string values may cause AVA to crash. You may see test failures if you were accidentally passing a non-string message. 49120aafd40c96bbe8196d3da8898d05006588d8
We've decided to remove the Flow type definitions from AVA itself. We don't have anybody to maintain them and consequently they've become a blocker when adding features to AVA. c633cf08891abaf7649d490642eef38b8150bfe0
We've set up a new repository from which we'll publish the definitions, but we need your help setting it up. If you use AVA and Flow, please join us in https://github.com/avajs/flow-typed/issues/1.
Test implementations may return observables. We've updated our TypeScript definition to require these to have a Symbol.observable
function. c2d8218ba78b26fe1368df183924757cd27555e4
AVA now uses the util.inspect.defaultOptions.depth
option when printing objects, so you can configure the depth. 98034fbb661bcc6cb882e1ae007a7877a803b3a4
You can now specify environment variables in your config, using the environmentVariables
object. a53ea157367c9cec91184cfbb226487c81229513
UntitledMacro
and UntitledCbMacro
types, for macro functions that will never have a .title
function. Though really this just helped simplify the type definition. Thanks @qlonik! ebf480779b826dcccc86376caf8ca5af4273e912test.skip(macro)
ba5cd804845517b1a5c4b04d1c08253ef27133d3Thank you @StoneCypher, @LukasHechenberger, @lo1tuma, @htor, @alexisfontaine and @grnch. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
⚠️ If you're looking to upgrade from 1.4.1, make sure to read the Beta 1 and Beta 2 release notes.
AVA now exposes some methods to our ESLint plugin, allowing our plugin to support the new test & helper file selection. 51433bed947d31e5f3df26bdf6eee10ad4344efa
AVA now uses the util.inspect.defaultOptions.depth
option when printing objects. 98034fbb661bcc6cb882e1ae007a7877a803b3a4
Thank you @grnch. We couldn't have done this without you!
We welcome new contributors. AVA is a friendly place to get started in open source. We have a great articleon getting started contributing and a comprehensive contributing guide.
Published by novemberborn over 5 years ago
⚠️ If you're looking to upgrade from 1.4.1, make sure to read the Beta 1 release notes.
Symbol.observable
function. c2d8218ba78b26fe1368df183924757cd27555e4AVA now also selects files ending with .spec.js
when looking for tests. 08e99e516e13af75d3ebe70f12194a89b610217c
You can now specify custom globs to select helper files:
{
"ava": {
"helpers": [
"**/helpers/**/*"
]
}
}
test.skip(macro)
ba5cd804845517b1a5c4b04d1c08253ef27133d3Thank you @StoneCypher, @LukasHechenberger, @lo1tuma, @htor and @alexisfontaine. We couldn't have done this without you!
We welcome new contributors. AVA is a friendly place to get started in open source. We have a great articleon getting started contributing and a comprehensive contributing guide.
Published by novemberborn over 5 years ago
Per the Node.js release schedule, the 6.x releases reach end of live on April 30th. Consequently we've removed support in AVA. We are now testing with Node.js 12 though. 3a4afc6cf35aeffb6b019c6b75fa9b8e071bb53d
We've been working on simplifying how test files and helpers are selected. First off, the files
option now only accepts glob patterns. If you configured it with directories before, please add /**/*
to get the previous behavior.
The files
and sources
options must now be arrays containing at least one pattern. It's no longer possible to override a default exclusion pattern, but we're looking at making these configurable separately.
AVA used to treat all files inside a helpers
directory as test helpers. Finding these files could be really slow, however, and it also meant you couldn't have tests inside a helpers
directory. Instead we're going to let you specify glob patterns to find these helpers. That work hasn't landed yet. For now, if you have such helpers we'd advise to not upgrade to this release.
Test files starting with an underscore are still recognized as helpers.
Files inside fixtures
directories are no longer ignored, and will now be treated as test files. The watcher now also watches ava.config.js
files.
The CLI now only takes file paths, not glob patterns.
We'd like some help updating our ESLint plugin as well.
When you run tests locally and add a new snapshot, AVA automatically updates the .snap
file. However if you forget to commit this file and then run your CI tests, they won't fail because AVA quietly updates the .snap
file, just like it does locally.
With this release, AVA will fail the t.snapshot()
assertion if it is run in CI and no snapshot could be found. 0804107b49ef3bb43656cd48d27b0d54ea080d71
AVA now enforces assertion messages to be strings. The message is only used when the assertion fails, and non-string values may cause AVA to crash. You may see test failures if you were accidentally passing a non-string message. 49120aafd40c96bbe8196d3da8898d05006588d8
We've decided to remove the Flow type definitions from AVA itself. We don't have anybody to maintain them and consequently they've become a blocker when adding features to AVA. c633cf08891abaf7649d490642eef38b8150bfe0
We've set up a new repository from which we'll publish the definitions, but we need your help setting it up. If you use AVA and Flow, please join us in https://github.com/avajs/flow-typed/issues/1.
UntitledMacro
and UntitledCbMacro
types, for macro functions that will never have a .title
function. Though really this just helped simplify the type definition. Thanks @qlonik! ebf480779b826dcccc86376caf8ca5af4273e912We 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.
Published by novemberborn over 5 years ago
power-assert
AVA comes with power-assert
built-in, giving you more descriptive assertion messages. However it's been confusing to understand which assertions come with power-assert
. To address this we've added the new t.assert()
assertion. It's now the only assertion that is power-assert
enabled. The assertion passes if called with a truthy value. Consider this example:
test('enhanced assertions', t => {
const a = /foo/;
const b = 'bar';
const c = 'baz';
t.assert(a.test(b) || b === c);
});
Value is not truthy:
false
a.test(b) || b === c
=> false
b === c
=> false
c
=> 'baz'
b
=> 'bar'
a.test(b)
=> false
b
=> 'bar'
a
=> /foo/
Our ESLint plugin has been updated to support this new assertion. Many thanks to @eemed for implementing this! 94064702837583f1cd3920142c5d0ce50e71e255
Watch mode now prints the available commands. Thanks @KompKK! cd256ac53c975d51ddabd3d80a9f909424f5d7e3
--match
, .skip()
or .only()
) are no longer included in the list of pending tests when timeouts occur or when you interrupt a test run. Thanks @vancouverwill! 23e302a8dc35d03ba82916bd6591822a28d499d1Thank you @eemed, @KompKK, @vancouverwill, @okyantoro and @amokmen. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
t.throws()
and t.throwsAsync()
. If you'd set a code
expectation to a number we never actually checked that the thrown error had such a code! Thanks to @qlonik for both spotting and fixing this. 82daa5e373ef0587693927acc63ce5590e8d8eb2clearTimeout()
, you'd break AVA. That's now been fixed. 40f331c27e70690e724f9ddc893fed0556058987You can now use require()
in ava.config.js
files to load non-ES modules. 334e15b4af06492c9aed2800a0764f245d6a908b
Thank you @itaisteinherz, @jdalton, @kagawagao, @KompKK, @SleeplessByte, @Chrisyee22 and @qlonik for helping us with this release. We couldn't have done this without you!
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.
Published by novemberborn over 5 years ago
This is a bug fix release. In very large projects, the options send to worker processes would exceed limits on process argument size. We're now sending the options via the inter-process communication channel. 3078892236c4f78409cc8475ed88f07d1141c0f0
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.
Published by novemberborn over 5 years ago
You can now set a timeout for test themselves. The test will fail if this timeout is exceeded. The timeout is reset each time an assertion is made:
test('foo', t => {
t.timeout(100); // 100 milliseconds
// Write your assertions here
});
b65c6d7da8ba3c7274f36dbcbcff26485f27d36f
AVA also has a global timeout feature. The mini reporter now logs tests that were pending when those timeouts occur. Additionally, if you interrupt a test using ctrl+c we'll now also show the pending tests. 2b60556360bb3b434ee5b4bb3486acb8a32b7aa7
Thank you @dflupu for your hard work on this!
workspaceFolder
variable 0a5fe429ca37c025a15c5af919827436cc413abc and --serial
argument placement edfc0055fea4fc204ac98c391baaa2ad60b41079💖 Huge thanks to @anishkny, @CrispusDH, @dflupu and @niktekusho for helping us with this release. We couldn’t have done it without you!
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.
Published by novemberborn almost 6 years ago
AVA now exports a meta
object. Currently, you can retrieve the path of the test file being run:
import test from 'ava';
console.log('Test currently being run: ', test.meta.file);
import {meta} from 'ava';
console.log('Test currently being run: ', meta.file);
This is useful in helpers that need to know the test file. bccd297f38c9f4cf6dbb16dffa7ee8753dbbd12f
t.log()
now works in hooks d1877122cea7ce54455d9dcc2bca046612dbd628
Error output for improper usage of t.throws()
once again links to the correct documentation dc552bcb57181d9b6d9c39711013f9813ddc2c51
We've added a section on webpack aliases to the Babel recipe c3bcbf2a568c12017fe0da041dc247a226019001
We've updated the Vue recipe for Babel 7, and added a section on webpack aliases c3bcbf2a568c12017fe0da041dc247a226019001
💖 Huge thanks to @fitztrev, @forresst, @astrob0t, @pearofducks, @coreyfarrell and @dflupu for helping us with this release. We couldn’t have done it without you!
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.
Published by novemberborn almost 6 years ago
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.
t.throws()
behavior & t.throwsAsync()
We've rewritten t.throws()
so it behaves better, has better error output and lets you write better tests:
You have a few ways of asserting that the exception is as designed. You can pass a second argument:
message
should be equal to it.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:
t.throws(fn, {code: 'ENOTFOUND'}) // err.code === 'ENOTFOUND'
t.throws(fn, {code: 9}) // err.code === 9
t.throws(fn, {instanceOf: SyntaxError}) // err instanceof SyntaxError
t.throws(fn, {is: expectedErrorInstance}) // err === expectedErrorInstance
t.throws(fn, {message: 'expected error message'}) // err.message === 'expected error message'
t.throws(fn, {message: /expected error message/}) // /expected error message/.test(err.message)
t.throws(fn, {name: 'SyntaxError'}) // err.name === 'SyntaxError'
This makes tests like these much easier to write:
// Old assertion
const err = t.throws(fn, TypeError)
t.is(err.message, 'Expected a string')
// New assertion
t.throws(fn, {
instanceOf: TypeError,
message: 'Expected a string'
})
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 completey.
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 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:
$ npx jscodeshift -t https://gist.githubusercontent.com/novemberborn/c2cdc94020083a1cafe3f41e8276f983/raw/eaa64c55dfcda8006fc760054055372bb3109d1c/transform.js test.js
Change test.js
to a glob pattern that matches your test files. See the jscodeshift CLI usage documentation for further details.
Assertion methods are now bound to the test, meaning you can provide them as direct arguments to other functions. A contrived example:
const assertEach = (arr, assert) => {
arr.forEach(value => assert(value));
};
test('all are true', t => {
assertEach(getArray(), t.true);
});
Whilst not strictly assertions, t.plan()
and t.log()
are now also bound to the test.
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.
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
:
{
"ava": {
"babel": {
"testOptions": {
"presets": [
["ava/stage-4", false]
]
}
}
}
}
Or, you can disable just ES module compilation:
package.json
:
{
"ava": {
"babel": {
"testOptions": {
"presets": [
["ava/stage-4", {"modules": false}]
]
}
}
}
}
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
:
{
"ava": {
"babel": false,
"compileEnhancements": false
}
}
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.
AVA now forwards arguments, provided after an --
argument terminator, to the worker processes. Arguments are available from process.argv[2]
onwards.
npx ava test.js -- hello world
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.
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.
npx ava --reset-cache
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:
export default {
babel: {
extensions: ['js', 'jsx']
}
};
Or export a factory function:
export default ({projectDir}) => ({
babel: {
extensions: ['js', 'jsx']
}
});
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.
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
:
{
"ava": {
"babel": {
"extensions": ["js", "jsx"]
}
}
}
Or define generic extensions, e.g. for use with TypeScript:
package.json
:
{
"ava": {
"compileEnhancements": false,
"extensions": ["ts"],
"require": [
"ts-node/register"
]
}
}
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
.
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 backwards 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.
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.
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:
import test, {Macro} from 'ava'
const failsToParse: Macro<[Buffer]> = (t, input) => {
t.throws(parse(input))
}
failsToParse.title = (providedTitle = 'unexpected input') => `throws when parsing ${providedTitle}`
test('malformed', failsToParse, fs.readFileSync('fixtures/malformed.txt'))
test(failsToParse, '}') // ⬅️ fails to compile
require
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.ci-parallel-vars
package for a list of supported CI environments.assert
module in Node.js 10 no longer crashes.process.stderr
is now emulated in the worker processes.--verbose
.<React.Fragment>
can be used in t.deepEqual
.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.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.
You can no longer do:
test(t => t.pass());
Instead all tests must have titles, and they must be unique within the test file:
test('passes', t => t.pass());
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:
test(function myTest (t) {
t.pass();
});
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()
..only
and .skip
must be used at the end, e.g. test.skip()
. 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()
..always
can only be used after .after
and .afterEach
, e.g. test.after.always()
..todo()
is only available on test
and test.serial
. No further modifiers can be applied.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
exportWe'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'
.
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:
import test from 'ava'
const failsToParse = (t, input) => {
t.throws(parse(input))
}
failsToParse.title = (providedTitle = 'unexpected input') => `throws when parsing ${providedTitle}`
test('malformed', failsToParse, fs.readFileSync('fixtures/malformed.txt'))
test(failsToParse, Buffer.from('}', 'utf8'))
This is a breaking change if you were concatenating the provided title, under the assumption that it was an empty string.
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:
$ npx jscodeshift -t https://gist.githubusercontent.com/novemberborn/c2cdc94020083a1cafe3f41e8276f983/raw/eaa64c55dfcda8006fc760054055372bb3109d1c/transform.js test.js
Change test.js
to a glob pattern that matches your test files. See the jscodeshift CLI usage documentation for further details.
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.
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.
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.
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.
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.
t._test
value has been removed@std/esm
, in favor of the plain esm
package.ava/stage-4
preset is applied after all other plugins and presets.null
as the this
value.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.--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.async
/await
support.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.
💖 Huge thanks to @okyantoro, @JasonRitchie, @forresst, @mdvorscak, @kugtong33, @motss, @BusbyActual, @billyjanitsch, @Briantmorr, @jdalton, @malimichael, @martypdx, @clemtrek, @samuelli, @emilyschultz, @hallettj, @isnifer, @Jaden-Giordano, @good-idea, @jamiebuilds, @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!
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.
Published by novemberborn almost 6 years ago
Okay then, barring any surprises, the next release is the 1.0. But first, there's some changes we want to get out while we work on the celebratory blog post 😉
Please give this release a try and let us know of any problems. And as always with pre-releases, be sure to install an exact dependency. However unlikely, there may still be breaking changes between now and the final 1.0 release:
npm install --save-dev --save-exact ava@next
Please see the release notes for the previous betas:
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. a130a9e3d9729e746b1ad9882ffc20de5b434750
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:
import test from 'ava'
const failsToParse = (t, input) => {
t.throws(parse(input))
}
failsToParse.title = (providedTitle = 'unexpected input') => `throws when parsing ${providedTitle}`
test('malformed', failsToParse, fs.readFileSync('fixtures/malformed.txt'))
test(failsToParse, Buffer.from('}', 'utf8'))
This is a breaking change if you were concatenating the provided title, under the assumption that it was an empty string. aa35f154e7cd3685f705dd07419f55af7b7440e5
When using TypeScript, you must now type the arguments used by the macro 6f54db84199473edcd169059acbd0bebc7427f04:
import test, {Macro} from 'ava'
const failsToParse: Macro<[Buffer]> = (t, input) => {
t.throws(parse(input))
}
failsToParse.title = (providedTitle = 'unexpected input') => `throws when parsing ${providedTitle}`
test('malformed', failsToParse, fs.readFileSync('fixtures/malformed.txt'))
test(failsToParse, '}') // ⬅️ fails to compile
esm
37390e6e8fbb911a52838926910973229f7a02af💖 Huge thanks to @forresst, @sh7dm and @qlonik for helping us with this release. We couldn’t have done it without you!
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.
Published by novemberborn about 6 years ago
With this release AVA supports babel.config.js
files. We've also improved our cache invalidation when you change your Babel configuration, so we're just about ready to ship the final 1.0 release 🎉
Please give this release a try and let us know of any problems. And as always with pre-releases, be sure to install an exact dependency. There may still be breaking changes between now and the 1.0 release:
$ npm install --save-dev --save-exact ava@next
Please see the release notes for the previous betas:
babel.config.js
support. ff09749e936fb005155fff715b0325a0b02a36c1 We're still looking for some help with updating the documentation, see https://github.com/avajs/ava/issues/1816.--verbose
. 6d12abfdff4478a1b6f4e87237764b89eb05f18dWe now support BigInt
and <React.Fragment>
in t.deepEqual()
and t.snapshot()
. We've also improved support for the Symbol.asyncIterator
well-known symbol. Unfortunately these changes are not backwards compatible. You'll need to update your snapshots when upgrading to this release. 71eede72c4984fa7bf8f7655a0088aa5615e8c39
profile.js
now handles extensions
configuration. 30a80b6e2fb90cdb0d7ce9a5878ea985d4ede7bdt.throws()
with asynchronous functions, AVA now suggests you use t.throwsAsync()
instead. f125b4df36ea0e6c552b9ac61278a8fa93521a6eava.config.js
configuration in an ava
property. f93b341d2a7c3d7b86f64f366722353f484a4e90💖 Huge thanks to @grant37, @xxczaki, @jamiebuilds, @robertbernardbrown, @lo1tuma, @goooseman, @wmik and @vancouverwill for helping us with this release. We couldn’t have done it without you!
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.