Commit graph

907 commits

Author SHA1 Message Date
Matthew Douglass
f243cab3b3
Do not count writes to stdout/stderr as non-idling activity for timeouts
Fixes #3373. The idle guard will now force a test worker to exit even if it's continuously writing to stdout/stderr.

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2025-04-15 21:59:32 +02:00
Mark Wubben
4abb780b5b
Update dependencies
* Update local node & npm versions through Volta

* Update non-TypeScript dev dependencies

* Update TypeScript dependencies & test matrix

* Update regular dependencies

* Rebuild lockfile
2025-04-14 21:55:05 +02:00
bojavou
86185b4ef7
Add filterNodeArgumentsForWorkerThreads option
This filter function can be used to remove node arguments that may be applied to the main process, but cannot be used to start worker threads. It can only be configured in a JavaScript configuration file. It does not apply when using child processes.

Co-authored-by: Tommy <tmitchell7@uh.edu>
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2024-08-20 15:55:43 +02:00
Mark Wubben
b15df53939
Update dependencies & other general maintenance
* Upgrade XO
* Update TypeScript-related dependencies — Don't upgrade @sindresorhus/tsconfig to v6 since it requires TS 5.5 and we test with 5.2.
* Update dev dependencies
* Update dependencies
* Rebuild lockfile
* Upgrade CodeCov action
* Update reporter log instructions and remove deprecation warnings
* Make Node.js 22.6 the recommended development version
* Remove Node.js 21 from the engines list: It's no longer maintained by Node.js itself, see also <https://github.com/avajs/ava/blob/main/docs/support-statement.md>.
2024-08-20 15:40:08 +02:00
Richard Gibson
be5000aac1
Fix throws assertions rejecting falsy values when any: true
Fixes #3312
2024-02-28 21:51:55 +01:00
Notas Hellout
1d62caf585
Upgrade xo to v0.57.0
* Upgrade xo to v0.57.0 and lint sources, tests, and examples

Disabled `unicorn/prevent-abbreviations` because it introduces too many
opinionated changes.

* Update reporter logs which are sensitive to line numbers changing

---------

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2024-02-27 22:24:21 +01:00
Mark Wubben
db0fdb2925 Fix 'previous failures' in watch mode always incrementing
The counters used absolute paths for the test files, but the clearing logic used relative paths. Count using relative paths instead.

The number of previous failures is not observable to the test harness, so this does not come with test coverage.

Fixes #3295.
2024-01-28 21:33:40 +01:00
Mark Wubben
0a050243ea Implement registerCompletionHandler()
Register a function to be called when AVA has completed a test run without uncaught exceptions or unhandled rejections.

Fixes #3279.
 *
 * Completion handlers are invoked in order of registration. Results are not awaited.
2024-01-11 22:33:57 +00:00
Mark Wubben
cc8b839724 Ensure AVA exits with code 1 after an unexpected process.exit() in a test worker
It prints the error, so it should fail as such.
2024-01-11 22:33:57 +00:00
Mark Wubben
35f6c86bcd Fix potential bug with watch mode when no failed test files are written
Don't emit the 'touched-files' event, since the watcher assumes that comes with a files value.

Fixes #3285
2024-01-11 22:33:27 +00:00
Mark Wubben
808a5613c9 Change recursive watch mode test detection to be non-persistent
Otherwise, on Linux, it seems the abort signal is disregarded.
2024-01-11 20:56:28 +00:00
Mark Wubben
9f3bf7e4d3
Remove references to older AVA versions
* 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
2023-12-30 20:58:44 +01:00
Mark Wubben
32f282fc21
Ensure watch mode works outside of its integration tests
Somewhere between developing the watch mode and adding test coverage, a mechanism was introduced to control watch mode in its integration tests. Ironically watch mode relied on this mechanism and no longer worked in actual use.

Fixes #3270
2023-12-06 22:18:23 +01:00
Mark Wubben
af5684dff5
Don't force-exit after tests have completed
Fixes #1718.

With worker threads, this seems to stop AVA from detecting that the thread has exited, causing a hang.

Also remove flush logic implemented in #1722. Let's hope that current Node.js versions are better at flushing IPC before exiting.
2023-12-04 22:22:11 +01:00
Mark Wubben
88e433376a
Update dependencies & other minor tweaks
* Update dependencies

* Ignore snapshot fixture due to churn

* Remove errant log

* Update GHA actions

* Test type definition with TS 5.3

* Select latest LTS in Volta

* Remove unnecessary npx invocation

* Rebuild lockfile

* Work around legacy tap-based tests choking on our tsconfig.json

No idea why it's even resolving the config when there are no TypeScript tests to run.
2023-12-04 21:56:22 +01:00
Max Isom
adbfcde981
Experimentally expose internal events for custom reporters
Add a new `observeRunsFromConfig` experiment, which allows a test run to be observed by a function installed through an `ava.config.*` file.

The function has access to AVA's internal events, which can then be used to report to a file.

AVA's internal event structure is not currently covered by any SemVer guarantees, which is why this feature requires the experimental opt-in.

Does not currently support watch mode. Only the first run is observed.
2023-11-26 21:26:34 +01:00
Sindre Sorhus
6790d50202
Update memoize dependency 2023-11-26 20:55:33 +01:00
Mark Wubben
e07179bf4a
Remove ability to select AVA 5 watcher
When I first retained the AVA 5 logic, it was under the assumption AVA 6 would be released in the summer with another breaking release later in the year. It's now autumn, Node.js 16 is end of life, and for now it's just not worth having this logic around.

Depending on how well the watcher works I'm not opposed to having it as an experimental "select your watch mode" feature though.
2023-11-07 11:52:59 +01:00
Sindre Sorhus
cf0fa4ce5a
Update dependencies, rely on Node.js 18, other small changes
* Update dependencies
* Rely on Node.js 18 language features
* Other small changes
* Upgrade to tap@18
* Develop and test with typescript@5.2
* Rebuild lockfile

---------

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-11-06 21:46:04 +01:00
Mark Wubben
03a6723a11
Drop Node.js 16, upgrade minimal 18 and 20, test 21
* Drop support for Node.js 16
* Change expected Node.js 18 to 18.18
* Change expected Node.js 20 to 20.8
* Add Node.js 21 to the test matrix

* Change snapshot tests to compare decompressed bitstreams

The snapshots are compressed differently in Node.js 21. The compression has been stable for many versions but that is not a guarantee, see https://github.com/nodejs/node/issues/50138 for background.

Change tests to compare the decompressed data instead.
2023-10-23 13:56:52 +02:00
Mark Wubben
b6fbd5847a Make assertions throw
Fixes #3201.

Assertions now throw a `TestFailure` error when they fail. This error is not exported or documented and should not be used or thrown manually. You cannot catch this error in order to recover from a failure, use `t.try()` instead.

All assertions except for `throws` and `throwsAsync` now return `true` when they pass. This is useful for some of the assertions in TypeScript where they can be used as a type guard.

Committing a failed `t.try()` result now also throws.
2023-10-22 21:40:24 +02:00
Aditya Subramanian
e81f413f5a
Allow throws / throwsAsync to work with any value, not just errors
Fixes #2517.

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-09-11 13:12:20 +02:00
Mark Wubben
4c5b46981a Refactor error processing
This commit simplifies error serialization, relying on the advanced IPC for child processes & worker threads. Unnecessary code has been removed.

Possibly breaking changes:

* Renamed and removed fields from the undocumented AssertionError class, including the raw values
* Changes to the undocumented TAP output; stack traces are a bit worse, the rest is about the same but some fields have different names or values
* `nyc` stack frames are no longer ignored; we assume you're using the native code coverage tools
2023-09-10 15:26:35 +02:00
Mark Wubben
e58f466cc0
Only treat native errors as errors
* Track worker errors. They're not native due to https://github.com/nodejs/node/issues/48716, but we want to treat them as such anyway.
* Only treat native errors as errors
* Remove is-error dependency
* Document edge case where `error instanceof Error` can be true, yet AVA does not recognize `error` as an error

See also https://github.com/avajs/ava/pull/2911 for an earlier attempt.
2023-07-31 09:25:50 +02:00
Mark Wubben
f047694d86 Remove p-event dependency 2023-07-03 17:48:48 +02:00
Mark Wubben
75330201a7 Remove workaround for worker.terminate() crashes
Looks like the patch is included in all supported Node.js versions.
2023-07-03 17:22:30 +02:00
Mark Wubben
10e2e8a35a Add t.timeout.clear() to restore default behavior 2023-07-03 15:46:29 +02:00
Mark Wubben
6ca0f1c6fb Pro-actively write out code coverage
This helped recording coverage when testing AVA itself, but hopefully it also helps user projects.
2023-07-02 20:50:24 +02:00
Mark Wubben
a6951cc3ab Lazy-load dependencies in CLI entrypoint 2023-07-02 17:26:14 +02:00
Mark Wubben
e5f19d9fc2 Modernize some syntax 2023-07-02 17:26:14 +02:00
Mark Wubben
c0b0d7bbb3 Move ignoredByWatcher to watchMode.ignoreChanges 2023-07-02 15:14:36 +02:00
Mark Wubben
4f52a9f1d3 Add a brand new watcher
Rely on recursive fs.watch(), rather than Chokidar. On Linux this is supported from Node.js 20 onwards. It won't work for network shares and Docker volume mounts which would require polling, we'll find out if that's a problem or not. (For now, the previous implementation is still available.)

Use @vercel/nft to perform static dependency analysis, supporting ESM and CJS imports for JavaScript & TypeScript source files. This is a huge improvement over the previous runtime tracking of CJS imports, which did not support ESM.

Rewrite the change handling logic to be easier to follow (though it's still pretty complicated).

Improve integration with `@ava/typescript`. The watcher can now detect a change to a TypeScript source file, then wait for the corresponding build output to change before re-running tests.
2023-07-02 15:14:36 +02:00
Mark Wubben
13f7451fd4 Require opt-in to AVA 5's watcher and separate install of chokidar
Restrict @ava/typescript to the ava-3.2 protocol, since the legacy code is not compatible with the ava-6 protocol.

Remove brittle tests for the legacy code.
2023-07-02 15:14:36 +02:00
Mark Wubben
94bb3619f1 Minor changes to watch mode
* Remove undocumented ability to start watch mode via the config. Require the CLI flag instead
* Watch mode is no longer 'relatively new'
* Add ava.config.mjs to default watcher ignore patterns
* Ignore changes to failed-tests file in watcher

Logger cleanup:

* Remove obsolete clearLogOnNextRun option
* Track firstRun for reporter
2023-07-02 15:14:36 +02:00
Bartłomiej Kalemba
4dc385b486
Enhance require feature
* Allow loading of ES modules
* Automatically invoke the default export (if any) and await the result
* Pass arguments from the config to the default export (relies on "advanced" IPC for child processes)
* Document that local files are loaded through the providers (e.g. `@ava/typescript`)

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-06-25 15:25:46 +02:00
Mark Wubben
1fff08d8b4 Remove checks against very old config options and related cleanup 2023-06-25 15:23:04 +02:00
Mark Wubben
fae3f8734f Use ES2022 APIs
* Use Object.hasOwn() instead of Reflect.has()
* Use Object.hasOwn() over Object.prototype.hasOwnProperty()
* Use String#replaceAll()
2023-06-25 15:23:04 +02:00
Mark Wubben
6398772595
Fix circular selector detection in t.like()
The previous implementation tracked each object, even if not circular. Update to use a stack.

Fixes #3205.
2023-06-16 18:23:54 +02:00
Richard Gibson
c988e27400
Support Symbol keys and ignore non-enumerable properties in t.like()
Fixes #3208

Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-06-16 17:38:43 +02:00
Mark Wubben
784ca4c381
Dependency updates and so forth
* Test against typescript@5.0

* Default to Node.js 20

* Upgrade XO

* Add reporter logs for Node.js 20

* Update dev dependencies

* Reduce timeouts in reporter tests

This may cause CI failures especially on Windows, but we do waste a lot of time with these tests.

* Inline slash dependency

We need it available in CJS but the package is now ESM only. It's more bothersome to remember to not upgrade the dependency than to inline it.

* Update dependencies

* Rebuild lockfile

* Use latest Codecov action
2023-05-24 16:58:05 +02:00
Irven Aelbrecht
555836793c
Recognize typical assertion errors and use their formatting
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-05-24 15:18:35 +02:00
Craig Hobbs
faa965474d
Replace 'del' dependency by built-in recursive fs.rm (#3198)
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-05-24 15:17:42 +02:00
Tommy
d7c612047a
Support arrays in t.like() assertion
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-05-24 15:17:16 +02:00
Matthew Espino
1c567642a3
Explicitly configure script name for CLI 2023-03-01 11:11:25 +01:00
Mark Wubben
da3d2bcffb
Update dependencies and such
* Upgrade XO and reformat

* Update dev dependencies

* Test with TypeScript 4.9

* Update dependencies

* Pin latest node@18 for Volta

* Use npm@9

* Rebuild lockfile

* Select Node.js version from Volta pin in most CI jobs

* Only pin npm when testing for lockfile churn; ensure npm@8 for Node.js 14
2023-01-15 21:33:33 +01:00
Max Isom
ffed948319
De-register all shared workers
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2023-01-15 18:29:23 +01:00
Max Isom
639b9050a6
Unref shared worker when all test workers have deregistered
This should prevent the main process from exiting prematurely with a 0 exit code. See background in https://github.com/avajs/ava/pull/3149#issuecomment-1345200868.
2022-12-13 16:00:41 +01:00
Filip Skokan
647d3e1530
Check for --config file extensions after they fail to load, allowing custom loaders (#3135)
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2022-11-13 17:41:14 +01:00
Kevin Tang
92069280a2
Output logs for tests that remain pending when AVA exits 2022-11-13 17:40:46 +01:00
Max
52b22700e9
Cap idle timeouts to the maximum possible value
Co-authored-by: creestor <maks.krivoshapov@gmail.com>
Co-authored-by: Mark Wubben <mark@novemberborn.net>
2022-09-05 11:33:35 +02:00