| 6 | import { READ_CHUNK_BYTES, createNodeTailSource } from "../streams/tail.js"; |
| 7 | |
| 8 | async function nextWithTimeout<T>( |
| 9 | iterator: AsyncIterator<T>, |
| 10 | timeoutMs = 2000, |
| 11 | ): Promise<IteratorResult<T>> { |
| 12 | let timer: ReturnType<typeof setTimeout> | undefined; |
| 13 | try { |
| 14 | return await Promise.race([ |
| 15 | iterator.next(), |
| 16 | new Promise<never>((_, reject) => { |
| 17 | timer = setTimeout(() => { |
| 18 | reject(new Error(`next() timed out after ${String(timeoutMs)}ms`)); |
| 19 | }, timeoutMs); |
| 20 | }), |
| 21 | ]); |
| 22 | } finally { |
| 23 | if (timer !== undefined) { |
| 24 | clearTimeout(timer); |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | test("createNodeTailSource yields existing + appended lines when fromEnd=false", async () => { |
| 30 | const dir = await mkdtemp(join(tmpdir(), "rezi-tail-")); |