feat(simulation): record viewport resizes (#36306)
This commit is contained in:
parent
6216dbae15
commit
be18f22842
8 changed files with 90 additions and 11 deletions
|
|
@ -2,6 +2,8 @@ import { expect, test } from "bun:test"
|
|||
import { mkdtemp, rm } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { TextRenderable } from "@opentui/core"
|
||||
import { createHarness, matches } from "../src/frontend/actions"
|
||||
import { SimulationRenderer } from "../src/frontend/renderer"
|
||||
import { Timeline, type Event } from "../src/recording"
|
||||
|
||||
|
|
@ -14,6 +16,7 @@ test("streams ANSI chunks into a versioned JSONL timeline", async () => {
|
|||
await new Promise<void>((resolve, reject) => {
|
||||
timeline.write(Buffer.from("\u001b[2Jhello"), (error) => (error ? reject(error) : resolve()))
|
||||
})
|
||||
timeline.resize(100, 30)
|
||||
expect(await timeline.finish()).toBe(path)
|
||||
await new Promise<void>((resolve) => timeline.write(Buffer.from("ignored"), () => resolve()))
|
||||
|
||||
|
|
@ -26,6 +29,7 @@ test("streams ANSI chunks into a versioned JSONL timeline", async () => {
|
|||
if (events[1]?.type !== "output") throw new Error("Missing output event")
|
||||
expect(Buffer.from(events[1].data, "base64").toString()).toBe("\u001b[2Jhello")
|
||||
expect(events[1].at_ms).toBeGreaterThanOrEqual(0)
|
||||
expect(events[2]).toMatchObject({ type: "resize", cols: 100, rows: 30 })
|
||||
expect(events.at(-1)).toMatchObject({ type: "output", data: "" })
|
||||
} finally {
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
|
|
@ -53,3 +57,20 @@ test("captures native renderer output and finishes on destroy", async () => {
|
|||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
test("matches live screen text while recording", async () => {
|
||||
const directory = await mkdtemp(join(tmpdir(), "simulation-recording-matches-"))
|
||||
const path = join(directory, "timeline.jsonl")
|
||||
const renderer = await SimulationRenderer.create({}, path)
|
||||
|
||||
try {
|
||||
renderer.root.add(new TextRenderable(renderer, { content: "recorded screen text" }))
|
||||
await SimulationRenderer.setupFor(renderer)?.renderOnce()
|
||||
|
||||
expect(matches(createHarness(renderer), "recorded screen text")).toBe(true)
|
||||
} finally {
|
||||
renderer.destroy()
|
||||
await SimulationRenderer.finish(renderer)
|
||||
await rm(directory, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue