Download packages/app/src/utils/terminal-writer.test.ts from SaylorTwift/opencode: direct link, hf CLI and curl.
- Browser
- Download file 1.39 kB
-
https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/terminal-writer.test.ts
- Command line
-
hf download hf://SaylorTwift/opencode/packages/app/src/utils/terminal-writer.test.ts
-
curl -L -o terminal-writer.test.ts https://huggingface.co/SaylorTwift/opencode/resolve/main/packages/app/src/utils/terminal-writer.test.ts
1.39 kB
| import { describe, expect, test } from "bun:test" | |
| import { terminalWriter } from "./terminal-writer" | |
| describe("terminalWriter", () => { | |
| test("buffers and flushes once per schedule", () => { | |
| const calls: string[] = [] | |
| const scheduled: VoidFunction[] = [] | |
| const writer = terminalWriter( | |
| (data, done) => { | |
| calls.push(data) | |
| done?.() | |
| }, | |
| (flush) => scheduled.push(flush), | |
| ) | |
| writer.push("a") | |
| writer.push("b") | |
| writer.push("c") | |
| expect(calls).toEqual([]) | |
| expect(scheduled).toHaveLength(1) | |
| scheduled[0]?.() | |
| expect(calls).toEqual(["abc"]) | |
| }) | |
| test("flush is a no-op when empty", () => { | |
| const calls: string[] = [] | |
| const writer = terminalWriter( | |
| (data, done) => { | |
| calls.push(data) | |
| done?.() | |
| }, | |
| (flush) => flush(), | |
| ) | |
| writer.flush() | |
| expect(calls).toEqual([]) | |
| }) | |
| test("flush waits for pending write completion", () => { | |
| const calls: string[] = [] | |
| let done: VoidFunction | undefined | |
| const writer = terminalWriter( | |
| (data, finish) => { | |
| calls.push(data) | |
| done = finish | |
| }, | |
| (flush) => flush(), | |
| ) | |
| writer.push("a") | |
| let settled = false | |
| writer.flush(() => { | |
| settled = true | |
| }) | |
| expect(calls).toEqual(["a"]) | |
| expect(settled).toBe(false) | |
| done?.() | |
| expect(settled).toBe(true) | |
| }) | |
| }) | |