Skip to content

async-operation-tracking

Test support: records fire-and-forget operations so a test can await them all.

It works by installing the AsyncOperationHook that production code reports to, so production code itself keeps no registry. The pending operations live on the installed hook, not in this module, so a second copy of this module reads the same registry the first one installed.

Function Description
disableAsyncOperationTracking Disables tracking previously enabled via enableAsyncOperationTracking and forgets any currently-tracked operations.
enableAsyncOperationTracking Enables tracking of fire-and-forget operations scheduled via invokeAsyncSafely (and therefore convertAsyncToSync). While enabled, each scheduled operation is recorded until it settles so that tests can await them all via waitForAllAsyncOperations, removing the need to override invokeAsyncSafely / convertAsyncToSync in tests. Tracking is disabled by default, so production code carries no bookkeeping overhead. Intended to be enabled in test environments only. Enabling it while it is already enabled keeps the operations already recorded.
isAsyncOperationTrackingEnabled Checks whether async-operation tracking is currently enabled (see enableAsyncOperationTracking).
waitForAllAsyncOperations Waits for all fire-and-forget operations tracked since enableAsyncOperationTracking was called to settle. Operations scheduled while awaiting are also awaited, so cascading fire-and-forget chains are fully drained.