sailfork / t3code-github / packages/ client-runtime/ src/ state/ commandOutput.test.ts

import { describe, expect, it } from "vite-plus/test";

import { applyCommandOutputFrame, EMPTY_COMMAND_OUTPUT } from "./commandOutput.ts";

describe("applyCommandOutputFrame", () => {
  it("continues an escape and a redraw split across appends", () => {
    let view = applyCommandOutputFrame(EMPTY_COMMAND_OUTPUT, {
      kind: "replace",
      text: "install\n12%\u001b[3",
      truncated: false,
      running: true,
    });
    expect(view.output.text).toBe("install\n12%");
    view = applyCommandOutputFrame(view, {
      kind: "append",
      text: "2m\r100%\u001b[0m\n",
      truncated: false,
      running: true,
    });
    // The colour opened before the redraw survives it.
    expect(view.output.text).toBe("install\n\u001b[0;32m100%\u001b[0m\n");
    expect(view.running).toBe(true);
  });
});