Skip to content

1.0.0-beta.2

Pre-release
Pre-release

Choose a tag to compare

@novemberborn novemberborn released this 14 Feb 16:24
14a842f

Continuing the work towards 1.0 🏗

This is the second beta release for AVA 1.0. You may want to read the release notes of the first beta to get up to speed.

This release uses [email protected]. We're waiting for Babel 7 to go out of beta before releasing the 1.0 version of AVA itself. This doesn't mean that these releases are any less stable than our previous 0.x versions though! If your project itself doesn't use Babel, or if your tests aren't coupled to your use of Babel 6 you should really upgrade.

Install this release using the next distribution tag:

$ npm install --save-dev ava@next

Many of our recipes are now out of date. There's a list of them in this issue. We'd love it if you could help us update these recipes.

Our ESLint plugin also needs some updates: avajs/eslint-plugin-ava#185, avajs/eslint-plugin-ava#186 & avajs/eslint-plugin-ava#187.

Breaking changes

New t.throws() behavior

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

  • The assertion takes a first thrower argument. This can be a function — which should throw an exception, return a rejected promise or an erroring observable — or a rejected promise, or an erroring observable.
  • The exception (or rejection reason, or observable error) must be an error object.
  • The assertion returns the exception (through a promise if necessary).

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

  • If you pass a function it should be a constructor: the exception must be an instance of it. Previously you could pass a validation function. This is no longer possible.
  • If you pass a string: the exception's message should be equal to it.
  • If you pass a regular expression: the exception's message should match it.

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

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'

t.notThrows() has also been updated but there aren't any breaking changes.

Modifier chaining

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

  • .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

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

New TypeScript and Flow definitions

The TypeScript and Flow definitions have been rewritten. The definitions export different interfaces so you may need to update your test code as well. The TypeScript recipe has been updated to reflect the changes, and there's a new Flow recipe as well (bac3c11, b2954a8).

Declaring tests

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

Serial hooks

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.

Pass CLI flags to your tests

AVA now forwards arguments, provided after an -- argument terminator, to the worker processes (ac300c1). Arguments are available from process.argv[2] onwards. There's a new recipe on how to use this.

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

Internals

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

  • The private t._test value has been removed
  • Some of the communication between the main process and the test workers has changed
  • Access to the options object from inside a worker process has changed

Other changes

  • t.context can now be used in .before and .after hooks (51a0ff0).

  • --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 (f83f8c0, 8de2630, c1b418f).

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

    test('all are true', t => {
      getArray().forEach(t.true);
    });

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

  • There's a new recipe on using ES modules (0b27db5)

  • We've also added a recipe on setting up tests (ae50a13)

All changes 📚

v1.0.0-beta.1...v1.0.0-beta.2

Thanks 💌

💖 Huge thanks to @jasonritchie, @forresst, @mdvorscak, @kugtong33 and @motss 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.