| 153 | } |
| 154 | |
| 155 | async function waitForAssertion(assertion: () => void): Promise<void> { |
| 156 | let lastError: unknown; |
| 157 | for (let attempt = 0; attempt < 20; attempt += 1) { |
| 158 | try { |
| 159 | assertion(); |
| 160 | return; |
| 161 | } catch (error) { |
| 162 | lastError = error; |
| 163 | await new Promise((resolve) => setTimeout(resolve, 0)); |
| 164 | } |
| 165 | } |
| 166 | throw lastError; |
| 167 | } |
| 168 | |
| 169 | async function runHandleMainCommand(opts: CLIOptions): Promise<number | null> { |
| 170 | const exitSpy = vi.spyOn(process, 'exit').mockImplementation((code?: string | number | null) => { |