Releases: avajs/ava
0.19.0
Since our last minor release, @novemberborn has worked tirelessly on refactoring big parts of the codebase to be more correct and readable, while squashing many bugs. We've also added multiple detections that will prevent user mistakes.
Highlights
Working snapshots
We released snapshot support with v0.18.0
, but unfortunately it didn’t work. That’s fixed now. Since we’re using jest-snapshot
the output will look a little different from AVA’s other assertions. Most notably the output will not be colored.
Tests fail if no assertions are run (BREAKING)
Sometimes you write a test that accidentally passes, because your assertion was never run. For example, the following test passes if getAnimals()
returns an empty array:
test('unicorn', t => {
for (const animal of getAnimals()) {
t.is(animal, 'unicorn');
}
});
AVA now fails your test if no assertions were run. This can be a problem if you use third-party assertion libraries, since AVA cannot detect when those assertions pass. You can disable this behavior by setting the failWithoutAssertions
option to false
in AVA's package.json
configuration.
Improved t.throws()
and t.notThrows()
assertions (BREAKING)
Various improvements have been made to these assertions. Unfortunately this does include some breaking changes.
Calling these assertions with an observable or promise makes them asynchronous. You now need to await
them:
const promise = Promise.reject(new TypeError('🦄'));
test('rejects', async t => {
await t.throws(promise);
});
Previously, these would return a promise that was rejected if the assertion failed. This leaked AVA’s internal assertion error. Now they’ll fulfill their returned promise with undefined
instead (d56db75). You typically won’t notice this in your test.
We’ve improved how we detect when t.throws()
and t.notThrows()
are used incorrectly (d924045). This might be when, rather than passing a function, you call it:
test('throws', t => {
t.throws(throwingFunction());
});
You can now use await
and yield
in the argument expressions (e.g. t.throws(await createThrowingFunction())
. The instructions on how to use these assertions correctly are now shown with the test failure, instead of being written to the console as your tests run.
Incorrectly using these assertions now always causes your test to fail.
Stack traces are now correct, even if used asynchronously (f6a42ba). The error messages have been improved for when t.throws()
fails to encounter an error, or if t.notThrows()
does (4463f38). If t.notThrows()
fails, the encountered error is shown (22c93ed).
Improved magic assert output
Actual and/or expected values are now included in the magic assert output, with helpful labels that are relevant to the failing assertion.
Detect hanging tests
AVA can now detect when an asynchronous test is hanging (880e87e).
Note that this may not work if your code is listening on a socket or is using a timer or interval.
Better Babel option resolution
We’re now resolving Babel options ahead of time, using hullabaloo-config-manager
. This fixes long-standing issues with relative paths in AVA’s "babel"
options in package.json
files (#707). It also means we’re better at recompiling test and helper files if your Babel config changes or you update plugins or presets.
Miscellaneous
- There is a new recipe for precompiling source files with webpack. a49f66b
- You can now type the test context when using TypeScript. 50ad213
- The color of text diff output has been fixed. 9f2ff09
- Text diffs are now faster. bd5ed60
- Values are no longer highlighted if colors are disabled. b581983
- AVA no longer crashes if tests fail with non-errors. 157ef25
- YAML blocks in the TAP output have been improved. 3279336
- We’re now printing assertion statements with less depth. 0510d80
- Arguments to
t.regex()
andt.notRegex()
are now validated. f062981
All changes
Thanks
💖 Huge thanks to @Wp1987, @lukechilds, @jakwuh, @danny-andrews, @mmkal, @yatharthk, @klauscfhq, @screendriver, @jhnns, @danez and @florianb 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.
0.18.2
Many bug fixes for snapshot testing, magic assert, and the type definitions: v0.18.1...v0.18.2
0.18.1
Quick bug fix: Remove t.is
and t.not
from enhanced assertion patterns to provide correct output on assertion failure.
0.18.0
This release is one of the biggest, most feature-packed release we’ve had in a long time. We have prepared lots of tasty things for you - snapshot testing, magic assert, precompiling test helpers, improvements to Babel transpilation, and more. Our team and contributors have been working hard to deliver all this goodness. We can’t wait to hear your feedback and don’t hesitate to suggest new ideas and report bugs!
Highlights
Dropped support for Node.js 0.10 and 0.12
As mentioned in the 0.17.0 release notes, we’re dropping support for Node.js 0.10 and 0.12 in this release. They’re both out of maintenance mode. Time to upgrade!
Magic assert
We completely overhauled the error output to make it as easy and fast as possible to detect the source of the failure. Magic assert, as we call it internally, adds code excerpts and clean diffs for actual and expected values. If values in the assertion are objects or arrays, only a difference is displayed to remove the noise and focus on the problem. Oh, and 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. Last but not least, you don’t have to update any of your tests to take advantage of this! Third-party assertion libraries, like expect, chai and others, are supported out-of-the-box as well.
Snapshot testing
We now have snapshot testing, thanks to @lithin ✨
Snapshot testing simply saves a stringified state of some data structure and compares it on the next run. It was popularized with React component testing, but you can use it with anything that can be stringified. For example, ensuring API responses stay the same.
ee65b6d
Precompile helper files
Previously, AVA transpiled your test files, but not your test helpers. Now we transpile helper files too! Helpers are files starting with _
or any files in a helpers
directory inside the test directory. These are usually used for utilities and shared logic between test files.
410cb8d
Improving language support
We’ve come up with a specification for how AVA handles Babel projects and may better support other languages like TypeScript. Customizing transpilation of test and helper files will be easier, and AVA will start transpiling source files too. We’ve started work on this, but there are no user-facing changes yet.
076eb81
Miscellaneous
- Removed deprecated assertions (
t.ok
,t.notOk
,t.same
,t.notSame
). If you haven’t migrated yet, you can do so automagically with our codemod. c010fd7 - Removed the
--source
flag. Use the package.json config instead. 34bebc4 - Support symlinked test files. 033d4dc
- No longer using
babel-runtime
. Built-ins likeMap
andPromise
are no longer replaced with polyfills. ad5122d - Prints a warning when
test.only()
is used, so you don’t mistakenly think you’re running all the tests. 22a6081 - Prints a warning when
--fail-fast
is enabled, so you’re aware AVA didn’t run all your tests. 09d23f5 - Exits with an error when
--watch
is used in CI, as otherwise the process would never exit, since watch mode is persistent. 0606ff7 - Only transpile what’s needed on Node.js 6. We already did that for Node.js 4. 5158ac8
- Flow type definition improvements: ce42fcb 314f7a0
- TypeScript type definition improvement: 0603edc
All changes
Thanks
💖 Huge thanks to @lithin, @ThomasBem, @leebyron, @rnkdev, @sebald, @gconaty, @jarlehansen, @LasaleFamine, @asafigan, 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.
0.17.0
The current working directory in test files changed (BREAKING)
We made the hard decision of changing the current working directory (process.cwd()
) in test files to be the same directory as package.json
. It was previously the same as __dirname
(the directory of the test file). Having process.cwd()
equal __dirname
felt like a good idea at the time, but as the popularity of AVA grew, people started hitting issues with it.
This affects users that have test files in a sub-folder and are using relative paths. If you have your test files in the same directory as package.json
, you're fine.
The fix is to wrap all relative paths in path.join(__dirname, 'relative-path')
to make them absolute.
Here's an example of what needs changing. The below file and unicorn.txt
are both in ./test/
.
-t.true(fs.existsSync('unicorn.txt'));
+t.true(fs.existsSync(path.join(__dirname, 'unicorn.txt')));
Let us know if anything is unclear or if you're having problems.
Commit: 476c653
Node.js version support
The next minor version of AVA, 0.18.0, will drop support for Node.js v0.10 and v0.12. We'll continue fixing critical issues for this version until the end of the year. Time to upgrade if you haven't. (Discussion: #1051)
Highlights
- We now have a script to automatically migrate from tape to AVA.
- Our ESLint plugin received two new rules:
- Reduced transpilation on Node.js >=4. AVA now only transpiles what's needed for Node.js 4 when on it or higher, which should result in better performance and stacktraces. 4025d81
- Removed the
--require
CLI flag. Configure it in package.json instead. 17119bc - Switched to
lodash.isEqual
for deep equality checking (t.deepEqual()
&t.notDeepEqual()
). This might make your test fail if our previous deep equality check was too loose. 8856684 - Improvements to the test failure output. e4f90e0 (We're currently working on many more improvements in this area. Stay tuned.)
- Added option to disable
power-assert
. 24a38ac - Correctly clean up stacktraces on Node.js 6 and higher. 26bcab0
- Removed
t.doesNotThrow()
as it was renamed tot.notThrows()
. It was deprecated far back in AVA 0.12.0. e448798 - Deprecated
t.error()
alias fort.ifError()
. It will be removed in AVA 1.0.0. Just uset.ifError()
. 28bb0d5 (We have an automatic migration script if you're usingt.error()
) - Ensures test files load correct AVA installation. This means you can now run AVA with an absolute path and it will still use the local AVA installation at that path if available. 3ea2ba1
- Added support for debugging tests with WebStorm and added a recipe. c268c8d
- Added Flow type defintion. 6458454
- Improvements to the TypeScript type definition. 4baa170 8816faf c40477a
- We started exploring browser support. 204f2be
All Changes
0.16.0
Hope you all are having a great summer! 😎
Highlights
- Add
t.notRegex()
. c740202 - Provide clear error message when users attempt nested or async calls to
test()
. 8edd9c2 - TypeScript definition improvements. 1dd6d5b 2e98438
- Document common pitfalls when using AVA. 187b8b4
- New JSPM and SystemJS recipe. c3539c1
All Changes
0.15.2
Avoids deprecation warning from loud-rejection
.
0.15.1
0.15.0
In this release we've added some very useful features we think you'll like. There are no known breaking changes. We have worked hard on fixing bugs and improving performance. Going forward stability and performance will be our top priority as we're progressing towards a stable release. Finally, we're delighted to welcome @sotojuan to the team! 🎉
Test file conventions
When you run AVA without any arguments, it tries to find your test files based on some conventions. The previous release had the following default patterns:
test.js test-*.js test/**/*.js
In this release we added additional default patterns based on community conventions:
test.js test-*.js test/**/*.js **/__tests__/**/*.js **/*.test.js
This means AVA will now also run test files in __tests__
directories and test files ending in .test.js
anywhere in your project.
Known failing tests
A big part of open source maintenance is triaging issues. This can be a tedious task, involving a lot of back and forth with the person reporting the issue. Submitting a PR with a failing test makes the whole process much more efficient. It helps maintainers by providing a quality reproduction, allowing them to focus on code over triaging. Users benefit as their bugs get fixed faster.
To make it easier to submit failing tests, we're introducing a new test modifier: test.failing()
. These tests are run just like normal ones, but they are expected to fail, and will not break your build when they do. If a test marked as failing actually passes, the build will break with a helpful message instructing you to remove the .failing
modifier.
test.failing('demonstrate some bug', t => {
t.fail(); // test will count as passed
});
This allows you to merge .failing
tests before a fix is implemented without breaking CI. It is also a great way to recognize good bug reports with a commit credit, even if the reporter is unable to fix the problem.
Test macros
Sometimes you want to run a series of very similar tests, each with different inputs and expected results. The traditional solution is to use test generator functions. However, this makes it difficult to perform static analysis on the tests, which is especially important for linting. In this release, we are introducing test macros as the official way to create reusable tests.
Test macros let you reuse test implementations. Additional arguments passed in the test declaration are forwarded to the macro:
function macro(t, input, expected) {
t.is(eval(input), expected);
}
test('2 + 2 === 4', macro, '2 + 2', 4);
test('2 * 3 === 6', macro, '2 * 3', 6);
If you are generating lots of tests from a single macro, you may want to generate the test title programmatically:
macro.title = (providedTitle, input, expected) => {
return `${input} === ${expected}`
};
Always modifiers for after and afterEach hooks
By default after
and afterEach
hooks will not be run if the preceding test fails. This is undesirable if the hooks contain cleanup code that you want run regardless. You can change that behavior using the .always
chaining modifier.
test.after.always(t => {
// always runs at the end. Regardless of test pass/fail state.
});
test.afterEach.always(t => {
// always runs after each test. Regardless of test pass/fail state.
});
Note that the --fail-fast
switch will disable this behavior, and AVA will exit at the first encountered failure without waiting for the always
hooks.
Limited concurrency [EXPERIMENTAL]
Concurrency is awesome! It's what makes AVA so fast. Our default behavior is to spin up an isolated process for every test file immediately, and then run all your tests. However, for users with lots of test files, this was eating up too many system resources, causing memory and IO thrashing. We are experimenting with an option to let you limit how many tests files AVA runs at the same time. If you have a lot of test files, try running AVA with the --concurrency
flag. For example, run $ ava --concurrency=5
and see if the performance improves. Please let us know how it works for you! We need feedback on the feature.
Note: This is an experimental feature and might change or be removed in the future.
Highlights
- Improve
t.deepEqual()
. 973624d - Improve watch logging. 95a5c97
- Disable TAP-reporter in watch mode. 02b0aae
- Throwing synchronously inside a callback-style test now fail it immediately. d6acdde
- Detect improper use of
t.throws
. 3201b1b - Protect against bad argument passed to
t.throws
. 60bd8a5 - Improve
power-assert
output. 84c05fe - Add spinner fallback for Windows. c4e58e3
- Warn about
npm link
usage on Node.js 6. a543b9f - Remember failures from previous tests in watch mode. aab2207
- Fix crash in 'fake' browser environment. 0fa229e
- Fix warning when no files are found. ee76aa9
- Strip ANSI escape codes in the TAP output. 3c4babd
- React recipe. 4c69c79
- Italian translation of the docs. 195390e
All Changes
We’ve merged 92 commits from 23 contributors since 0.14.0
. This only scratches the surface, as lots of additional work has gone into our linter, localized docs and countless other projects that make AVA possible. To everyone who’s reported bugs, contributed to design discussions, and filed PR’s with documentation or code - Thank You!
0.14.0
The biggest change in this release is the deprecation of t.ok
, t.notOk
, t.same
, and t.notSame
assertions. We have published a codemod (automatic migration script) which should make switching to the new assertion methods very easy.
Also, we've added a --timeout
flag that will stop test execution after a certain period of inactivity.
Highlights
- A number of assertion methods have been renamed for clarity. The old methods still exist, but have been deprecated, and will be removed in a future release (e9c6cc2, a7f50eb). We have published
ava-codemods
to assist in automatically renaming these assertions in your tests.t.ok()
→t.truthy()
t.notOk()
→t.falsy()
t.same()
→t.deepEqual()
t.notSame()
→t.notDeepEqual()
- Added an idle timeout option to prevent test runs from hanging indefinitely. The test run is considered timed out when no test results have been received for the specified interval. d1a3669
- Published a recipe on various ways to configure Babel. bcda753
- Updated Russian, Chinese, and Spanish translations. Big thanks to our translation team!
Of Note
t.deepEqual()
(formerlyt.same()
) no longer compares constructors. a7826cf- Truncate test titles in the mini reporter. 6d5f322
- Fix
t.throws()
not returning error for synchronous methods. 26d2291 - Now throws a meaningful error if
--require
dependency is not found. c78e736 - Watch mode will now rerun all
.only
tests regardless of dependency graph. e57908a - Print the planned and actual assertion count when there is a plan failure. 07febb2
- Workaround for Node.js bug which could kill main process. cd6961a
- Mini reporter no longer flashes test titles for
skip
/todo
tests. ecc87cb - Display a helpful error message for invalid Babel config. febbaa2
- Switch from
serialize-error
toclean-yaml-object
(better compatibility withnode-tap
). cd5767e - Rewrite
require("babel-runtime")
in tests to absolute path (allows module resolution fornpm@2
without modifyingNODE_PATHS
). 382e50d - Ensure source maps can be resolved from cached code. 592ff13
- Produces a helpful failure method when users incorrectly provide an implementation method to
test.todo()
. 8d6490a
All Changes
Shout-out to @kentcdodds @sotojuan @SamVerschueren @mattkrick for their awesome contributions to this release! ✨🎉