Skip to main content

What it flags

An async test acquires a local child process, HTTP listener, worker, file watcher, or interval and cleans it up after an await. A rejected promise can skip cleanup and leave the resource running, which can hang the test runner. The rule runs in recognized test and end-to-end files. It accounts for cleanup in a finally block that protects the wait and cleanup hooks registered before the wait, such as t.after, onTestFinished (from the test context or imported) or onTestFailed from the test context. It also stays quiet when, before the wait, a closure that performs the cleanup is passed to a call (t.teardown, stack.defer, cleanups.push) or held by a using declaration. Event listeners, timers and afterAll called inside a test do not count as teardown. Neither does an in-test afterEach that is imported from node:test, @jest/globals or bun:test, or called globally or on a runner such as test in a file that uses jest; other in-test afterEach calls, such as Mocha globals, are accepted. Cleanup that a handled rejection still reaches, after a catch block that neither throws nor returns or after .catch() on the awaited promise, is left alone. It leaves the resource alone when ownership passes to another function.

How to review or fix

Register a cleanup hook immediately after creating the resource, or wrap the work in try and put cleanup in finally. For example, in a Node.js test:

Configuration

Set the rule to "off" in loadwise.config.json to drop its findings: