| 61 | }; |
| 62 | |
| 63 | export class VirtualTimeController { |
| 64 | readonly #options: VirtualTimeOptions; |
| 65 | readonly #testController = new AbortController(); |
| 66 | readonly #tasks: TaskRecord[] = []; |
| 67 | readonly #timers = new Map<number, TimerEntry>(); |
| 68 | readonly #animationCallbacks = new Map<number, AnimationEntry>(); |
| 69 | readonly #idleCallbacks = new Map<number, IdleEntry>(); |
| 70 | readonly #trackedPromises = new Set<Promise<void>>(); |
| 71 | readonly #patches: PatchRecord[] = []; |
| 72 | readonly #reportedErrors: unknown[] = []; |
| 73 | |
| 74 | #nextId = 0; |
| 75 | #nextOrder = 0; |
| 76 | #now = 0; |
| 77 | #taskExecutions = 0; |
| 78 | #firstError: unknown; |
| 79 | #hasError = false; |
| 80 | #installed = false; |
| 81 | #animationConfigured = false; |
| 82 | #idleConfigured = false; |
| 83 | #idleBudget: number; |
| 84 | #manualOperations = 0; |
| 85 | #manualWaiters: Array<() => void> = []; |
| 86 | #microtaskCount = 0; |
| 87 | #usesNodeHandles = false; |
| 88 | |
| 89 | constructor(options: VirtualTimeOptions) { |
| 90 | this.#options = options; |
| 91 | this.#idleBudget = options.idleBudget; |
| 92 | } |
| 93 | |
| 94 | get signal(): AbortSignal { |
| 95 | return this.#testController.signal; |
| 96 | } |
| 97 | |
| 98 | now(): number { |
| 99 | return this.#now; |
| 100 | } |
| 101 | |
| 102 | install(): void { |
| 103 | if (this.#installed) { |
| 104 | throw new Error('Virtual time is already installed.'); |
| 105 | } |
| 106 | this.#installed = true; |
| 107 | this.#usesNodeHandles = |
| 108 | typeof ( |
| 109 | globalThis as { |
| 110 | process?: { versions?: { node?: string } }; |
| 111 | } |
| 112 | ).process?.versions?.node === 'string'; |
| 113 | |
| 114 | try { |
| 115 | this.#installTimers(); |
| 116 | this.#installAnimationFrames(); |
| 117 | this.#installIdleCallbacks(); |
| 118 | this.#installImmediate(); |
| 119 | this.#installAbortSignalTimeout(); |
| 120 | this.#installClocks(); |
nothing calls this directly
no outgoing calls
no test coverage detected