Skip to content

Commit

Permalink
Remove references to older AVA versions
Browse files Browse the repository at this point in the history
* Remove obsolete recipes

ES modules is supported out of the box.

The React recipe applies to AVA 3.

* Remove code guards against obsolete API usage

* Remove references to older AVA versions from documentation
  • Loading branch information
novemberborn authored Dec 30, 2023
1 parent 316ffe1 commit 9f3bf7e
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 251 deletions.
2 changes: 1 addition & 1 deletion docs/01-writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AVA tries to run test files with their current working directory set to the dire

## Test isolation

Each test file is run in a new worker thread. This is new as of AVA 4, though you can fall back to AVA 3's behavior of running in separate processes.
By default each test file is run in a new worker thread. You can fall back running in separate processes.

AVA will set `process.env.NODE_ENV` to `test`, unless the `NODE_ENV` environment variable has been set. This is useful if the code you're testing has test defaults (for example when picking what database to connect to). It may cause your code or its dependencies to behave differently though. Note that `'NODE_ENV' in process.env` will always be `true`.

Expand Down
12 changes: 5 additions & 7 deletions docs/03-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ test('unicorns are truthy', t => {

If multiple assertion failures are encountered within a single test, AVA will only display the *first* one.

In AVA 6, assertions return `true` if they've passed and throw otherwise. Catching this error does not cause the test to pass. The error value is undocumented.

In AVA 5, assertions return a boolean and do not throw. You can use this to return early from a test. The `snapshot()` assertion does not return a value.
Assertions return `true` if they've passed and throw otherwise. Catching this error does not cause the test to pass. The error value is undocumented.

If you use TypeScript you can use some assertions as type guards.

Note that the "throws" assertions return the error that was thrown (provided the assertion passed). In AVA 5, they return `undefined` if the assertion failed.
Note that the "throws" assertions return the error that was thrown (provided the assertion passed).

## Assertion planning

Expand Down Expand Up @@ -179,7 +177,7 @@ t.like([1, 2, 3, 4], [1, , 3])
Assert that an error is thrown. `fn` must be a function which should throw. By default, the thrown value *must* be an error. It is returned so you can run more assertions against it.
`expectation` can be an object with one or more of the following properties:

* `any`: a boolean only available in AVA 6, if `true` then the thrown value does not need to be an error. Defaults to `false`
* `any`: a boolean, if `true` then the thrown value does not need to be an error. Defaults to `false`
* `instanceOf`: a constructor, the thrown error must be an instance of
* `is`: the thrown error must be strictly equal to `expectation.is`
* `message`: the following types are valid:
Expand Down Expand Up @@ -214,7 +212,7 @@ Assert that an error is thrown. `thrower` can be an async function which should
By default, the thrown value *must* be an error. It is returned so you can run more assertions against it.
`expectation` can be an object with one or more of the following properties:

* `any`: a boolean only available in AVA 6, if `true` then the thrown value does not need to be an error. Defaults to `false`
* `any`: a boolean, if `true` then the thrown value does not need to be an error. Defaults to `false`
* `instanceOf`: a constructor, the thrown error must be an instance of
* `is`: the thrown error must be strictly equal to `expectation.is`
* `message`: the following types are valid:
Expand Down Expand Up @@ -279,7 +277,7 @@ Compares the `expected` value with a previously recorded snapshot. Snapshots are

The implementation function behaves the same as any other test function. You can even use macros. The first title argument is always optional. Additional arguments are passed to the implementation or macro function.

`.try()` is an asynchronous function. You must `await` it. The result object has `commit()` and `discard()` methods. You must decide whether to commit or discard the result. If you commit a failed result, your test will fail. In AVA 6, calling `commit()` on a failed result will throw an error.
`.try()` is an asynchronous function. You must `await` it. The result object has `commit()` and `discard()` methods. You must decide whether to commit or discard the result. If you commit a failed result, your test will fail. Calling `commit()` on a failed result will throw an error.

You can check whether the attempt passed using the `passed` property. Any assertion errors are available through the `errors` property. The attempt title is available through the `title` property.

Expand Down
3 changes: 0 additions & 3 deletions docs/recipes/es-modules.md

This file was deleted.

189 changes: 0 additions & 189 deletions docs/recipes/react.md

This file was deleted.

4 changes: 1 addition & 3 deletions docs/recipes/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Note that, despite the type cast above, when executing `t.context` is an empty o

## Typing `throws` assertions

In AVA 6, the `t.throws()` and `t.throwsAsync()` assertions are typed to always return an `Error`. You can customize the error class using generics:
The `t.throws()` and `t.throwsAsync()` assertions are typed to always return an `Error`. You can customize the error class using generics:

```ts
import test from 'ava';
Expand Down Expand Up @@ -206,6 +206,4 @@ test('throwsAsync', async t => {
});
```

In AVA 5, the assertion is typed to return the `Error` if the assertion passes *or* `undefined` if it fails.

[`@ava/typescript`]: https://github.com/avajs/typescript
12 changes: 3 additions & 9 deletions docs/recipes/watch-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ Please note that integrated debugging and the TAP reporter are unavailable when

## Requirements

AVA 5 uses [`chokidar`] as the file watcher. Note that even if you see warnings about optional dependencies failing during install, it will still work fine. Please refer to the *[Install Troubleshooting]* section of `chokidar` documentation for how to resolve the installation problems with chokidar.

Otherwise, AVA 6 uses `fs.watch()`. Support for `recursive` mode is required. Note that this has only become available on Linux since Node.js 20. [Other caveats apply](https://nodejs.org/api/fs.html#caveats), for example this won't work well on network filesystems and Docker host mounts.
AVA uses `fs.watch()`. Support for `recursive` mode is required. Note that this has only become available on Linux since Node.js 20. [Other caveats apply](https://nodejs.org/api/fs.html#caveats), for example this won't work well on network filesystems and Docker host mounts.

## Ignoring changes

By default AVA watches for changes to all files, except for those with a `.snap.md` extension, `ava.config.*` and files in [certain directories](https://github.com/novemberborn/ignore-by-default/blob/master/index.js) as provided by the [`ignore-by-default`] package.

With AVA 5, you can configure additional patterns for files to ignore in the [`ava` section of your `package.json`, or `ava.config.*` file][config], using the `ignoredByWatcher` key.

With AVA 6, place these patterns within the `watchMode` object:
You can configure additional patterns for files to ignore in the [`ava` section of your `package.json`, or `ava.config.*` file][config], using the `ignoreChanges` key within the `watchMode` object:

```js
export default {
Expand All @@ -42,9 +38,7 @@ If your tests write to disk they may trigger the watcher to rerun your tests. Co

AVA tracks which source files your test files depend on. If you change such a dependency only the test file that depends on it will be rerun. AVA will rerun all tests if it cannot determine which test file depends on the changed source file.

AVA 5 spies on `require()` calls to track dependencies. Custom extensions and transpilers are supported, provided you [added them in your `package.json` or `ava.config.*` file][config], and not from inside your test file.

With AVA 6, dependency tracking works for `require()` and `import` syntax, as supported by [@vercel/nft](https://github.com/vercel/nft). `import()` is supported but dynamic paths such as `import(myVariable)` are not.
Dependency tracking works for `require()` and `import` syntax, as supported by [@vercel/nft](https://github.com/vercel/nft). `import()` is supported but dynamic paths such as `import(myVariable)` are not.

Files accessed using the `fs` module are not tracked.

Expand Down
7 changes: 0 additions & 7 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,13 +626,6 @@ export class Assertions {
}));
}

if (message?.id !== undefined) {
throw fail(new AssertionError('Since AVA 4, snapshot IDs are no longer supported', {
assertion: 't.snapshot()',
formattedDetails: [formatWithLabel('Called with id:', message.id)],
}));
}

assertMessage(message, 't.snapshot()');

if (message === '') {
Expand Down
6 changes: 1 addition & 5 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,10 @@ export default class Runner extends Emittery {
todo: true,
});
} else {
if (!implementation) {
if (typeof implementation !== 'function') {
throw new TypeError('Expected an implementation. Use `test.todo()` for tests without an implementation.');
}

if (Array.isArray(implementation)) {
throw new TypeError('AVA 4 no longer supports multiple implementations.');
}

if (title.isSet && !title.isValid) {
throw new TypeError('Test & hook titles must be strings');
}
Expand Down
6 changes: 1 addition & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ class ExecutionContext extends Assertions {

const {args, implementation, title} = parseTestArgs(attemptArgs);

if (!implementation) {
if (typeof implementation !== 'function') {
throw new TypeError('Expected an implementation.');
}

if (Array.isArray(implementation)) {
throw new TypeError('AVA 4 no longer supports t.try() with multiple implementations.');
}

let attemptTitle;
if (!title.isSet || title.isEmpty) {
attemptTitle = `${test.title} ─ attempt ${test.attemptCount + 1}`;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Alternatively you can install `ava` manually:
npm install --save-dev ava
```

*Make sure to install AVA locally. As of AVA 4 it can no longer be run globally.*
*Make sure to install AVA locally. AVA cannot be run globally.*

Don't forget to configure the `test` script in your `package.json` as per above.

Expand Down
13 changes: 0 additions & 13 deletions test-tap/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1538,19 +1538,6 @@ test('.snapshot()', async t => {
});
}

{
// See https://github.com/avajs/ava/issues/2669
const assertions = setup('id');
failsWith(t, () => assertions.snapshot({foo: 'bar'}, {id: 'an id'}), {
assertion: 't.snapshot()',
message: 'Since AVA 4, snapshot IDs are no longer supported',
formattedDetails: [{
label: 'Called with id:',
formatted: '\'an id\'',
}],
});
}

await manager.save();
t.end();
});
Expand Down
4 changes: 2 additions & 2 deletions test-tap/reporters/tap.regular.v18.log
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ not ok 12 - test › no longer failing
message: >-
Test was expected to fail, but succeeded, you should stop marking the test as
failing
at: 'Test.finish (/lib/test.js:633:28)'
at: 'Test.finish (/lib/test.js:629:28)'
...
---tty-stream-chunk-separator
not ok 13 - test › logs
Expand Down Expand Up @@ -144,7 +144,7 @@ not ok 15 - test › implementation throws non-error
details:
'Error thrown in test:': 'null'
message: Error thrown in test
at: 'Test.run (/lib/test.js:546:25)'
at: 'Test.run (/lib/test.js:542:25)'
...
---tty-stream-chunk-separator
not ok 16 - traces-in-t-throws › throws
Expand Down
Loading

0 comments on commit 9f3bf7e

Please sign in to comment.