Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

commandOutput.test.ts

53 lines1.7 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { applyCommandOutputFrame, EMPTY_COMMAND_OUTPUT } from "./commandOutput.ts";
4​
5describe("applyCommandOutputFrame", () => {
6 it("continues an escape and a redraw split across appends", () => {
7 let view = applyCommandOutputFrame(EMPTY_COMMAND_OUTPUT, {
8 kind: "replace",
9 text: "install\n12%\u001b[3",
10 truncated: false,
11 running: true,
12 });
13 expect(view.output.text).toBe("install\n12%");
14 view = applyCommandOutputFrame(view, {
15 kind: "append",
16 text: "2m\r100%\u001b[0m\n",
17 truncated: false,
18 running: true,
19 });
20 // The colour opened before the redraw survives it.
21 expect(view.output.text).toBe("install\n\u001b[0;32m100%\u001b[0m\n");
22 expect(view.running).toBe(true);
23 });
24​
25 it("starts over from the tail a reconnect sends, keeping only that", () => {
26 const stale = applyCommandOutputFrame(EMPTY_COMMAND_OUTPUT, {
27 kind: "replace",
28 text: "line 1\n",
29 truncated: false,
30 running: true,
31 });
32 const resumed = applyCommandOutputFrame(stale, {
33 kind: "replace",
34 text: "line 7\nline 8\n",
35 truncated: true,
36 running: true,
37 });
38 expect(resumed.output.text).toBe("line 7\nline 8\n");
39 expect(resumed.output.truncated).toBe(true);
40 });
41​
42 it("marks the output final when the command settles", () => {
43 const view = applyCommandOutputFrame(EMPTY_COMMAND_OUTPUT, {
44 kind: "replace",
45 text: "done\n",
46 truncated: false,
47 running: false,
48 });
49 expect(view.output.text).toBe("done\n");
50 expect(view.output.truncated).toBe(false);
51 expect(view.running).toBe(false);
52 });
53});