UNPKG

2.54 kBTypeScriptView Raw
1/**
2 * @type WaiterName
3 *
4 * A string representing the test waiter name
5 */
6export declare type WaiterName = string;
7/**
8 * @type Token
9 */
10export declare type Token = Primitive | unknown;
11/**
12 * @type Primitive
13 *
14 * Any of the primitive value types
15 */
16export declare type Primitive = string | number | boolean | symbol | bigint;
17/**
18 * @public
19 * @interface Waiter
20 */
21export interface Waiter {
22 /**
23 * A string representing the test waiter name.
24 *
25 * @public
26 * @property name {WaiterName}
27 */
28 name: WaiterName;
29 /**
30 * Used to determine if the waiter system should still wait for async
31 * operations to complete.
32 *
33 * @public
34 * @method waitUntil
35 * @returns {boolean}
36 */
37 waitUntil(): boolean;
38 /**
39 * Returns the `debugInfo` for each item tracking async operations in this waiter.
40 *
41 * @public
42 * @method debugInfo
43 * @returns {TestWaiterDebugInfo}
44 */
45 debugInfo(): TestWaiterDebugInfo[];
46}
47/**
48 * @public
49 * @interface TestWaiter<T>
50 */
51export interface TestWaiter<T extends object | Primitive | unknown = Token> extends Waiter {
52 /**
53 * Should be used to signal the beginning of an async operation that
54 * is to be waited for. Invocation of this method should be paired with a subsequent
55 * `endAsync` call to indicate to the waiter system that the async operation is completed.
56 *
57 * @public
58 * @method beginAsync
59 * @param item {T} The item to register for waiting
60 * @param label {string} An optional label to identify the item
61 */
62 beginAsync(token?: T, label?: string): T;
63 /**
64 * Should be used to signal the end of an async operation. Invocation of this
65 * method should be paired with a preceding `beginAsync` call from this instance,
66 * which would indicate the beginning of an async operation.
67 *
68 * @public
69 * @method endAsync
70 * @param item {T} The item to that was registered for waiting
71 */
72 endAsync(token: T): void;
73 /**
74 * Resets the waiter state, clearing items tracking async operations in this waiter.
75 *
76 * @public
77 * @method reset
78 */
79 reset(): void;
80}
81/**
82 * @public
83 * @interface TestWaiterDebugInfo
84 */
85export interface TestWaiterDebugInfo {
86 stack: string | undefined;
87 label: string | undefined;
88}
89/**
90 * @public
91 * @interface PendingWaiterState
92 */
93export interface PendingWaiterState {
94 pending: number;
95 waiters: {
96 [waiterName: string]: TestWaiterDebugInfo[] | true;
97 };
98}