( received: Record<string, unknown>[], pred: (frame: Record<string, unknown>) => boolean, timeoutMs = 2000, )
| 140 | } |
| 141 | |
| 142 | async function waitFor( |
| 143 | received: Record<string, unknown>[], |
| 144 | pred: (frame: Record<string, unknown>) => boolean, |
| 145 | timeoutMs = 2000, |
| 146 | ): Promise<Record<string, unknown>> { |
| 147 | const start = Date.now(); |
| 148 | while (Date.now() - start < timeoutMs) { |
| 149 | const hit = received.find(pred); |
| 150 | if (hit !== undefined) return hit; |
| 151 | await new Promise((resolve) => setTimeout(resolve, 10)); |
| 152 | } |
| 153 | throw new Error( |
| 154 | `waitFor timed out; received: ${received |
| 155 | .map((frame) => { |
| 156 | const frameType = typeof frame['type'] === 'string' ? frame['type'] : '(unknown)'; |
| 157 | const frameId = typeof frame['id'] === 'string' ? frame['id'] : ''; |
| 158 | return `${frameType}:${frameId}`; |
| 159 | }) |
| 160 | .join(', ')}`, |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | describe('terminal WS controls', () => { |
| 165 | it('attaches, replays output, forwards live output, input, resize, and close', async () => { |
no test coverage detected