Repository: avajs/ava
Pull request #3280 (2023-12-30 19:42:21)

Remove references to older AVA versions
- Remove obsolete recipes
- Remove code guards against obsolete API usage
- Remove references to older AVA versions from documentation



Patch:
diff --git a/docs/03-assertions.md b/docs/03-assertions.md
index 1613658e..f5800b06 100644
--- a/docs/03-assertions.md
+++ b/docs/03-assertions.md
@@ -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
 
@@ -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:
@@ -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:
@@ -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.
 
diff --git a/docs/recipes/es-modules.md b/docs/recipes/es-modules.md
deleted file mode 100644
index 6358063b..00000000
--- a/docs/recipes/es-modules.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Using ES modules in AVA
-
-AVA 4 supports ES modules out of the box.
diff --git a/docs/recipes/react.md b/docs/recipes/react.md
deleted file mode 100644
index edb792fc..00000000
--- a/docs/recipes/react.md
+++ /dev/null
@@ -1,189 +0,0 @@
-# Testing React components with AVA 3
-
-Translations: [Español](https://github.com/avajs/ava-docs/blob/main/es_ES/docs/recipes/react.md), [Français](https://github.com/avajs/ava-docs/blob/main/fr_FR/docs/recipes/react.md)
-
-**AVA 4 no longer has built-in Babel support, and `t.snapshot()` and `t.deepEqual()` no longer recognize React elements either. Therefore this recipe is mostly relevant for AVA 3 users.**
-
-## Setting up Babel
-
-When you [enable Babel](https://github.com/avajs/babel), AVA 3 will automatically extend your regular (project-level) Babel configuration. You should be able to use React in your test files without any additional configuration.
-
-However if you want to set it up explicitly, add the preset to the test options in AVA's Babel pipeline by modifying your `package.json` or `ava.config.*` file.
-
-**`package.json`:**
-
-```json
-{
-	"ava": {
-		"babel": {
-			"testOptions": {
-				"presets": ["@babel/preset-react"]
-			}
-		}
-	}
-}
-```
-
-You can find more information in [`@ava/babel`](https://github.com/avajs/babel).
-
-## Using [Enzyme](https://github.com/airbnb/enzyme)
-
-Let's first see how to use AVA with one of the most popular React testing libraries: [Enzyme](https://github.com/enzymejs/enzyme).
-
-If you intend to only use [shallow component rendering](https://facebook.github.io/react/docs/test-utils.html#shallow-rendering), you don't need any extra setup.
-
-### Install Enzyme
-
-First install [Enzyme and its required adapter](https://github.com/enzymejs/enzyme#installation):
-
-```console
-$ npm install --save-dev enzyme enzyme-adapter-react-16
-```
-
-### Set up Enzyme
-
-Create a helper file, prefixed with an underscore. This ensures AVA does not treat it as a test.
-
-`test/_setup-enzyme-adapter.js`:
-
-```js
-import Enzyme from 'enzyme';
-import Adapter from 'enzyme-adapter-react-16';
-
-Enzyme.configure({
-	adapter: new Adapter()
-});
-```
-
-### Configure tests to use Enzyme
-
-Configure AVA to `require` the helper before every test file.
-
-**`package.json`:**
-
-```json
-{
-	"ava": {
-		"require": [
-			"./test/_setup-enzyme-adapter.js"
-		]
-	}
-}
-```
-
-### Enjoy
-
-Then you can use Enzyme straight away:
-
-`test.js`:
-
-```js
-import test from 'ava';
-import React from 'react';
-import PropTypes from 'prop-types';
-import {shallow} from 'enzyme';
-
-const Foo = ({children}) =>
-	<div className="Foo">
-		<span className="bar">bar</span>
-		{children}
-		<span className="bar">bar</span>
-	</div>;
-
-Foo.propTypes = {
-	children: PropTypes.any
-};
-
-test('has a .Foo class name', t => {
-	const wrapper = shallow(<Foo/>);
-	t.true(wrapper.hasClass('Foo'));
-});
-
-test('renders two `.Bar`', t => {
-	const wrapper = shallow(<Foo/>);
-	t.is(wrapper.find('.bar').length, 2);
-});
-
-test('renders children when passed in', t => {
-	const wrapper = shallow(
-		<Foo>
-			<div className="unique"/>
-		</Foo>
-	);
-	t.true(wrapper.contains(<div className="unique"/>));
-});
-```
-
-Enzyme also has a `mount` and `render` helper to test in an actual browser environment. If you want to use these helpers, you will have to setup a browser environment. Check out the [browser testing recipe](https://github.com/avajs/ava/blob/main/docs/recipes/browser-testing.md) on how to do so.
-
-To see an example of AVA working together with Enzyme set up for browser testing, have a look at [this sample project](https://github.com/adriantoine/ava-enzyme-demo).
-
-This is a basic example on how to integrate Enzyme with AVA. For more information about using Enzyme for unit testing React component, have a look at [Enzyme's documentation](https://enzymejs.github.io/enzyme/).
-
-## Using JSX helpers
-
-Another approach to testing React component is to use the [`react-element-to-jsx-string`](https://github.com/algolia/react-element-to-jsx-string) package to compare DOM trees as strings. [`jsx-test-helpers`](https://github.com/MoOx/jsx-test-helpers) is a nice library handling [shallow component rendering](https://facebook.github.io/react/docs/test-utils.html#shallow-rendering) and converting JSX to string in order to test React components using AVA assertions.
-
-```console
-$ npm install --save-dev jsx-test-helpers
-```
-
-Usage example:
-
-```js
-import test from 'ava';
-import React from 'react';
-import PropTypes from 'prop-types';
-import {renderJSX, JSX} from 'jsx-test-helpers';
-
-const Foo = ({children}) =>
-	<div className="Foo">
-		<span className="bar">bar</span>
-		{children}
-		<span className="bar">bar</span>
-	</div>;
-
-Foo.propTypes = {
-	children: PropTypes.any
-};
-
-test('renders correct markup', t => {
-	const actual = renderJSX(<Foo/>);
-	const expected = JSX(
-		<div className="Foo">
-			<span className="bar">bar</span>
-			<span className="bar">bar</span>
-		</div>
-	);
-	t.is(actual, expected);
-});
-
-test('renders children when passed in', t => {
-	const actual = renderJSX(
-		<Foo>
-			<div className="unique"/>
-		</Foo>
-	);
-	const expected = JSX(
-		<div className="Foo">
-			<span className="bar">bar</span>
-			<div className="unique"/>
-			<span className="bar">bar</span>
-		</div>
-	);
-	t.is(actual, expected);
-});
-```
-
-Note that you have to use variables like `actual` and `expected` because [`power-assert` doesn't handle JSX correctly](https://github.com/power-assert-js/power-assert/issues/34).
-
-This is a basic example on how to use `jsx-test-helpers` with AVA. To see a more advanced usage of this library, have a look at [this annotated test file](https://github.com/MoOx/jsx-test-helpers/blob/master/src/__tests__/index.js).
-
-[This sample project](https://github.com/MoOx/jsx-test-helpers) shows a basic and minimal setup of AVA with `jsx-test-helpers`.
-
-## Using other assertion libraries
-
-In AVA, you can use any assertion library, and there are already a few out there to test React components. Here is a list of assertion libraries working well with AVA:
-
-- [`expect-jsx`](https://github.com/algolia/expect-jsx) ([Example](https://github.com/avajs/ava/issues/186#issuecomment-161317068))
-- [`unexpected-react`](https://github.com/bruderstein/unexpected-react) ([Sample project with an output example](https://github.com/adriantoine/ava-unexpected-react-demo))
diff --git a/docs/recipes/typescript.md b/docs/recipes/typescript.md
index 0a629841..e110a4c5 100644
--- a/docs/recipes/typescript.md
+++ b/docs/recipes/typescript.md
@@ -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';
@@ -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
diff --git a/docs/recipes/watch-mode.md b/docs/recipes/watch-mode.md
index 83003122..39d7c4be 100644
--- a/docs/recipes/watch-mode.md
+++ b/docs/recipes/watch-mode.md
@@ -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 {
@@ -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.
 
diff --git a/lib/assert.js b/lib/assert.js
index f4d5ff51..9e93d31f 100644
--- a/lib/assert.js
+++ b/lib/assert.js
@@ -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 === '') {
diff --git a/lib/runner.js b/lib/runner.js
index d81c11ad..8c80f227 100644
--- a/lib/runner.js
+++ b/lib/runner.js
@@ -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');
 				}
diff --git a/readme.md b/readme.md
index 77015cf1..fd7161e0 100644
--- a/readme.md
+++ b/readme.md
@@ -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.
 


Test patch:
diff --git a/docs/01-writing-tests.md b/docs/01-writing-tests.md
index abec90c3..35c4a902 100644
--- a/docs/01-writing-tests.md
+++ b/docs/01-writing-tests.md
@@ -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`.
 
diff --git a/lib/test.js b/lib/test.js
index e821c9f7..caccda84 100644
--- a/lib/test.js
+++ b/lib/test.js
@@ -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}`;
diff --git a/test-tap/assert.js b/test-tap/assert.js
index 4ba1e4f5..633814a8 100644
--- a/test-tap/assert.js
+++ b/test-tap/assert.js
@@ -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();
 });
diff --git a/test-tap/reporters/tap.regular.v18.log b/test-tap/reporters/tap.regular.v18.log
index 7686951e..5ff5a137 100644
--- a/test-tap/reporters/tap.regular.v18.log
+++ b/test-tap/reporters/tap.regular.v18.log
@@ -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
@@ -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
diff --git a/test-tap/reporters/tap.regular.v20.log b/test-tap/reporters/tap.regular.v20.log
index 7686951e..5ff5a137 100644
--- a/test-tap/reporters/tap.regular.v20.log
+++ b/test-tap/reporters/tap.regular.v20.log
@@ -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
@@ -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
diff --git a/test-tap/reporters/tap.regular.v21.log b/test-tap/reporters/tap.regular.v21.log
index 7686951e..5ff5a137 100644
--- a/test-tap/reporters/tap.regular.v21.log
+++ b/test-tap/reporters/tap.regular.v21.log
@@ -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
@@ -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
diff --git a/test/multiple-implementations/test.js b/test/multiple-implementations/test.js
index 4cefc477..1bbeeecb 100644
--- a/test/multiple-implementations/test.js
+++ b/test/multiple-implementations/test.js
@@ -4,10 +4,10 @@ import {fixture} from '../helpers/exec.js';
 
 test('test()', async t => {
 	const result = await t.throwsAsync(fixture(['test.js']));
-	t.regex(result.stdout, /AVA 4 no longer supports multiple implementations/);
+	t.regex(result.stdout, /Expected an implementation/);
 });
 
 test('t.try()', async t => {
 	const result = await t.throwsAsync(fixture(['try.js']));
-	t.regex(result.stdout, /AVA 4 no longer supports t\.try\(\) with multiple implementations/);
+	t.regex(result.stdout, /Expected an implementation/);
 });