0.20.0
Today’s release is very exciting. After adding magic assert and snapshot testing we found that these features sometimes disagreed with each other. t.deepEqual()
would return false
, yet AVA wouldn’t show a diff. Snapshot tests cared about Set
order but t.deepEqual()
didn’t. @novemberborn came to the realization that comparing and diffing object trees, and doing so over time with snapshots, are variations on the same problem. Thus he started ConcordanceJS, a new project that lets you compare, format, diff and serialize any JavaScript value. This AVA release reaps the fruits of his labor.
Highlights
More magical asserts
Magic assert will now always show the difference between actual and expected values. If an unexpected error occurs it’ll print all (enumerable) properties of the error which can make it easier to debug your program.
More details of an object are printed, like the constructor name and the string tag. Buffers are hex-encoded with line breaks so they’re easy to read:
t.deepEqual()
improvements
t.deepEqual()
and t.notDeepEqual()
now use concordance
, rather than lodash.isequal
. This changes what values AVA considers to be equal, making the t.deepEqual()
assertion more predictable. You can now trust that all aspects of your objects are compared.
Object wrappers are no longer equal. The following assertion will now fail:
t.deepEqual(Object(1), 1); // fails
For Map
and Set
objects to be equal, their elements must now be in the same order:
const actual = new Set(['hello', 'world']);
t.deepEqual(actual, new Set(['hello', 'world'])); // passes
t.deepEqual(actual, new Set(['world', 'hello']) // fails
With this release AVA will compare all enumerable properties of an object. For an array this means that the comparison considers not just the array elements. The following are no longer considered equal:
const actual = [1, 2, 3];
const expected = [1, 2, 3];
expected.also = 'a property';
t.deepEqual(actual, expected); // fails
The same goes for Map
and Set
objects, errors, and so forth:
const actual = new TypeError('Bad value');
const expected = new TypeError('Bad value');
expected.value = 41;
t.deepEqual(actual, expected); // fails
You used to be able to compare Arguments
object to an object literal:
const args = (function() { return arguments; })('hello', 'world');
t.deepEqual(args, {0: 'hello', 1: 'world'}); // now fails
Instead you must now use:
const args = (function() { return arguments; })('hello', 'world');
t.deepEqual(args, ['hello', 'world']); // passes
(Of course you can still compare Arguments
objects to each other.)
New in this release is the ability to compare React elements:
t.deepEqual(<HelloWorld/>, <HelloWorld/>);
const renderer = require('react-test-renderer');
t.deepEqual(renderer.create(<HelloWorld/>).toJSON(), <h1>Hello World</h1>);
Snapshot improvements
Snapshots too now use concordance
. This means values are compared with the snapshot according to the same rules as t.deepEqual()
, albeit with some minor differences:
Argument
objects can only be compared toArgument
objects- Functions are compared by name and other enumerable properties
- Promises are compared by their constructor and additional enumerable properties
- Symbols are compared by their string serialization. Registered and well-known symbols will never equal symbols with similar descriptions
Note that Node.js versions before 6.5 cannot infer names of all functions . AVA will pass a snapshot assertion if it determines the name information is unreliable.
AVA now saves two files when snapshotting. One, ending in the .snap
extension, contains a compressed serialization of the expected value. The other is a readable Markdown file that contains the snapshot report. You should commit both to source control. The report file can be used to see what is in your snapshots and to compare snapshot changes over time.
Try it out with our snapshot example! Or check out an example snapshot report.
The snapshot file location now follows your test layout. If you use a test
folder, they’ll be placed in test/snapshots
. With __tests__
they’ll be placed in __tests__/__snapshots__
. And if you just have a test.js
in your project root the snapshot files will be written to test.js.snap
and test.js.md
. You may have to manually remove old snapshot files after installing this new AVA version. ebd572a
Improved snapshot support in watch mode
In watch mode, AVA now watches for changes to snapshot files. This is handy when you revert changes while the watcher is running. Snapshot files are correctly tracked as test dependencies, so the right tests are rerun. Typing u
, followed by Enter
updates the snapshots in the tests that just ran. (And the watcher won’t rerun tests when snapshots are updated.) 87eef84 dbc78dc f507e36 50b60a1
Node.js 8 support
AVA 0.19 already worked great with Node.js 8, and we’ve made it even better by removing unnecessary Babel transpilations in our stage-4
preset. We’re now also forwarding the --inspect-brk
flag for debugging purposes. e456951 a868b02
New and improved recipes
We’ve added new recipes and improved others:
- Learn how to debug tests with Visual Studio Code 1d04153 140c0e0
- Test MongoDB integrations with per-test isolation 970872c
- Using AVA with Vue.js ff3bba9
- There’s several ways of using webpack to precompile tests and sources. We’ve broken down the pros and cons f228401
- We’ve added a note to the browser testing recipe, discouraging the use of
browser-env
c01ac05
Miscellaneous
- Specifying
--concurrency
without a value now causes AVA to exit with an error 8c35a1a - Using
t.throws()
with a resolved promise now prints a helpful error message dfca2d9 - The
t.title
accessor has been documented. 549e99b
All changes
Thanks
💖 Huge thanks to @lukechilds, @alexrussell, @zs-zs, @cncolder, @JPeer264, @CImrie, @blake-newman, @yatharthk, @bfred-it, @tdeschryver, @sudo-suhas, @dohomi, @efegurkan and @forresst 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.