Buckets:
| 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) | |
| }) | |
| }) | |
Xet Storage Details
- Size:
- 1.39 kB
- Xet hash:
- d053f1dcaa245fb376478bedc4ebf34856bfa24496d964b3a43455c61e0a3e14
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.