avajs / ava

Node.js test runner that lets you develop with confidence 🚀
MIT License
20.74k stars 1.41k forks source link

config to control handling for tests that 'Failed to exit' - v6+ issue #3279

Closed croconut closed 10 months ago

croconut commented 10 months ago

With Node 18.18, I am unable to get Ava to not fail the test suite when a module does not exit. I run integration tests with a local database and want to keep the database pool open.

In 5.3.1, this worked fine but it breaks after upgrading and no other changes on my end.

Please enable some kind of way to set up the configuration to forcibly exit and pass if all tests ran & passed, or just let me know what I'm missing here. I've already tried toggling worker threads and I didnt see anything else usable in the docs for the configuration.

novemberborn commented 10 months ago

This was discussed here: https://github.com/avajs/ava/pull/3260#issuecomment-1856198505

But I'll use this as the tracking issue.


I run integration tests with a local database and want to keep the database pool open.

Since each test file runs in its own isolated worker thread, I don't think this will make a difference.

In 5.3.1, this worked fine but it breaks after upgrading and no other changes on my end.

Yes this was a change in AVA 6. It's listed under the Breaking Changes in the release notes:

When tests finish, worker threads or child processes are no longer exited through proces.exit(). If your test file does not exit on its own, the test run will time out.

Please enable some kind of way to set up the configuration to forcibly exit and pass if all tests ran & passed

See suggestion at https://github.com/avajs/ava/pull/3260#issuecomment-1856198505:

I think a import { registerCompleteHandler } from 'ava' which sets up a function to be called when AVA is done would be a decent solution. You could then registerCompleteHandler(() => process.exit()) and AVA will just assume the test worker exited on its own. This could be in a helper file that is loaded.

Other use cases are as a cleanup routine that sits outside of AVA's test & hook logic. I'm leaning to a solution like this over configuration because configuration implies we can handle edge cases in Node.js and we can't.

novemberborn commented 10 months ago

@croconut let me know if https://github.com/avajs/ava/pull/3283 works for you.

croconut commented 10 months ago

@novemberborn thanks a bunch, I'll give this a shot