UNPKG

@coinbase/onchaintestkit

Version:

End-to-end testing toolkit for blockchain applications, powered by Playwright

69 lines (68 loc) 2.25 kB
import { RetryOptions } from "./RetryStrategy"; export interface WatchOptions { timeout: number; retryOptions?: RetryOptions; signal?: AbortSignal; description?: string; } export interface ConditionResult<T> { value: T; timestamp: number; attempts: number; } export declare class WatchTimeoutError extends Error { constructor(description: string, timeout: number, attempts: number); } export declare class WatchAbortedError extends Error { constructor(description: string); } /** * Observable-like condition watcher for replacing simple polling patterns */ export declare class ConditionWatcher<T> { private condition; private options; private startTime; private attempts; private constructor(); /** * Create a new condition watcher */ static watch<T>(condition: () => Promise<T | null>, options: WatchOptions): ConditionWatcher<T>; /** * Wait until the condition returns a non-null value */ waitUntil(): Promise<ConditionResult<T>>; /** * Wait until the condition returns a value that matches the predicate */ waitUntilMatches(predicate: (value: T) => boolean): Promise<ConditionResult<T>>; /** * Transform the watched value before returning */ map<U>(transform: (value: T) => U): ConditionWatcher<U>; /** * Add a filter to the condition */ filter(predicate: (value: T) => boolean): ConditionWatcher<T>; /** * Add a timeout to the watcher */ timeout(ms: number): ConditionWatcher<T>; /** * Add retry configuration */ withRetryOptions(retryOptions: RetryOptions): ConditionWatcher<T>; /** * Add a description for better error messages */ describe(description: string): ConditionWatcher<T>; private shouldContinue; private sleep; /** * Static helper methods for common patterns */ static waitForCondition<T>(condition: () => Promise<T | null>, timeout: number, description?: string): Promise<T>; static waitForElement(locator: () => Promise<Element | null>, timeout?: number): Promise<Element>; static waitForValue<T>(getter: () => Promise<T | null | undefined>, timeout?: number, description?: string): Promise<T>; }