/** * Deterministic virtual clock for testing durable workflows. * * Does NOT monkey-patch global timers. Instead, provides an explicit * `now` property and a `schedule` method for registering timer callbacks * that fire when virtual time is advanced past their target. * * @module testing/time-control */ import type { Duration } from '../core/types'; /** * Deterministic virtual clock for testing durable workflows that depend on * time-based behaviour (timers, delays, scheduling). * * Does NOT monkey-patch global timers. Instead, provides an explicit `now` * property and an `advance` method that fires registered callbacks in * chronological order as virtual time moves forward. Use this inside a * {@link TestEngine} to write fully deterministic timer tests. * * @example * ```ts * import { TimeControl } from '@lostgradient/weft/testing'; * * const clock = new TimeControl(0); * let fired = false; * * clock.schedule(5_000, () => { * fired = true; * }); * * await clock.advance('5s'); * console.log(fired); // true * console.log(clock.now); // 5000 * ``` */ export declare class TimeControl { #private; constructor(startTime?: number); /** Current virtual time in milliseconds since epoch. */ get now(): number; /** * Advance time by duration. Fires all timers that fall within the * window, in chronological order. */ advance(duration: Duration): Promise; /** Advance time to a specific timestamp. Throws if in the past. */ advanceTo(timestamp: number): Promise; /** * Schedule a timer callback at a specific virtual time. * Returns a cancel function. */ schedule(fireAt: number, callback: () => void | Promise): () => void; /** Number of pending (non-cancelled, not-yet-fired) timers. */ get pendingTimerCount(): number; /** Peek at the next timer's fire time. */ get nextTimerAt(): number | undefined; /** Reset to initial state. */ reset(startTime?: number): void; }