Support Custom Signal Listeners or a Global afterAll
Hook in deno test
#27681
Labels
testing
related to deno test and coverage
afterAll
Hook in deno test
#27681
Description
It appears that when defining tests with
Deno.test()
and running them usingdeno test
, adding custom signal listeners (e.g.Deno.addSignalListener
) does not work as expected. Thedeno test
runner seems to ignore these listeners, as the signals are only handled internally within the test runner's Rust implementation.In my use case, I am building a test wrapper that awaits a global asynchronous teardown function during a final test step. While this works well during normal test execution, I want the teardown function to be triggered even when the test suite exits unexpectedly, such as when a
SIGINT
orSIGTERM
signal is received.Here is a simplified example:
However, when running the test suite with
deno test
, the signal listener is never triggered. Instead, thedeno test
runner uses its own signal handler and outputs the following when interrupted:This behavior prevents custom signal listeners from being used to handle cleanup tasks or shutdown hooks effectively.
Feature Request
To make
deno test
more flexible and customizable for advanced test scenarios, I propose one of the following enhancements:Support for Custom Signal Listeners:
Deno.addSignalListener
) in addition to the test runner's default handlers.SIGINT
orSIGTERM
and execute custom logic, such as cleanup functions, before the process exits.A Global
afterAll
Hook:afterAll
hook that is executed after all tests complete, regardless of how the test suite terminates (e.g., normal exit or signal interruption).afterAll
hook would allow users to register teardown logic that ensures proper cleanup before the process exits.Expected Behavior
Deno.addSignalListener
is registered, the test runner should invoke the user's listener(s) in addition to its own internal signal handling.afterAll
hook would provide a standardized way to execute cleanup logic at the end of the test suite, regardless of how the suite terminates.Use Case
This feature would enable advanced test suite behaviors, such as:
Current Behavior
Currently,
deno test
:Conclusion
Adding support for custom signal listeners or a global
afterAll
hook would greatly enhance the flexibility and usability of thedeno test
runner, especially for users with complex test suite requirements.Thank you for considering this feature request! I'm happy to provide further details or examples if needed.
The text was updated successfully, but these errors were encountered: