Skip to content

Commit 1fbd006

Browse files
committed
test(web): format xterm host reconnect specs
1 parent e338e38 commit 1fbd006

1 file changed

Lines changed: 89 additions & 75 deletions

File tree

packages/web/src/features/terminal-panel/__tests__/xterm-host.test.tsx

Lines changed: 89 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,37 +3318,39 @@ describe("XtermHost", () => {
33183318
mockTerminal.cols = 132;
33193319
mockTerminal.rows = 36;
33203320

3321-
sendCommand.mockImplementation((op: string, args: { terminalId?: string; lastSeq?: number }) => {
3322-
if (op === "terminal.snapshot") {
3323-
snapshotCount += 1;
3324-
return Promise.resolve({
3325-
status: "ok",
3326-
transport: "binary",
3327-
streamId: 945,
3328-
size: firstSnapshot.byteLength,
3329-
seq: 200,
3330-
rows: 36,
3331-
cols: 132,
3332-
source: "headless",
3333-
bytes: firstSnapshot,
3334-
} satisfies TerminalSnapshotPayload);
3335-
}
3321+
sendCommand.mockImplementation(
3322+
(op: string, args: { terminalId?: string; lastSeq?: number }) => {
3323+
if (op === "terminal.snapshot") {
3324+
snapshotCount += 1;
3325+
return Promise.resolve({
3326+
status: "ok",
3327+
transport: "binary",
3328+
streamId: 945,
3329+
size: firstSnapshot.byteLength,
3330+
seq: 200,
3331+
rows: 36,
3332+
cols: 132,
3333+
source: "headless",
3334+
bytes: firstSnapshot,
3335+
} satisfies TerminalSnapshotPayload);
3336+
}
33363337

3337-
if (op === "terminal.replay") {
3338-
replayCount += 1;
3339-
expect(args.lastSeq).toBe(200);
3340-
return Promise.resolve({
3341-
status: "ok",
3342-
transport: "binary",
3343-
streamId: 946,
3344-
size: reconnectReplay.byteLength,
3345-
seq: 240,
3346-
bytes: reconnectReplay,
3347-
} satisfies TerminalReplayPayload);
3348-
}
3338+
if (op === "terminal.replay") {
3339+
replayCount += 1;
3340+
expect(args.lastSeq).toBe(200);
3341+
return Promise.resolve({
3342+
status: "ok",
3343+
transport: "binary",
3344+
streamId: 946,
3345+
size: reconnectReplay.byteLength,
3346+
seq: 240,
3347+
bytes: reconnectReplay,
3348+
} satisfies TerminalReplayPayload);
3349+
}
33493350

3350-
return Promise.resolve({ status: "ok" });
3351-
});
3351+
return Promise.resolve({ status: "ok" });
3352+
}
3353+
);
33523354

33533355
store.set(wsClientAtom, {
33543356
sendCommand,
@@ -3414,37 +3416,39 @@ describe("XtermHost", () => {
34143416
mockTerminal.cols = 132;
34153417
mockTerminal.rows = 36;
34163418

3417-
sendCommand.mockImplementation((op: string, args: { terminalId?: string; lastSeq?: number }) => {
3418-
if (op === "terminal.snapshot") {
3419-
snapshotCount += 1;
3420-
return Promise.resolve({
3421-
status: "ok",
3422-
transport: "binary",
3423-
streamId: 950,
3424-
size: firstSnapshot.byteLength,
3425-
seq: 200,
3426-
rows: 36,
3427-
cols: 132,
3428-
source: "headless",
3429-
bytes: firstSnapshot,
3430-
} satisfies TerminalSnapshotPayload);
3431-
}
3419+
sendCommand.mockImplementation(
3420+
(op: string, args: { terminalId?: string; lastSeq?: number }) => {
3421+
if (op === "terminal.snapshot") {
3422+
snapshotCount += 1;
3423+
return Promise.resolve({
3424+
status: "ok",
3425+
transport: "binary",
3426+
streamId: 950,
3427+
size: firstSnapshot.byteLength,
3428+
seq: 200,
3429+
rows: 36,
3430+
cols: 132,
3431+
source: "headless",
3432+
bytes: firstSnapshot,
3433+
} satisfies TerminalSnapshotPayload);
3434+
}
34323435

3433-
if (op === "terminal.replay") {
3434-
replayCount += 1;
3435-
expect(args.lastSeq).toBe(200);
3436-
return Promise.resolve({
3437-
status: "ok",
3438-
transport: "binary",
3439-
streamId: 951,
3440-
size: reconnectReplay.byteLength,
3441-
seq: 240,
3442-
bytes: reconnectReplay,
3443-
} satisfies TerminalReplayPayload);
3444-
}
3436+
if (op === "terminal.replay") {
3437+
replayCount += 1;
3438+
expect(args.lastSeq).toBe(200);
3439+
return Promise.resolve({
3440+
status: "ok",
3441+
transport: "binary",
3442+
streamId: 951,
3443+
size: reconnectReplay.byteLength,
3444+
seq: 240,
3445+
bytes: reconnectReplay,
3446+
} satisfies TerminalReplayPayload);
3447+
}
34453448

3446-
return Promise.resolve({ status: "ok" });
3447-
});
3449+
return Promise.resolve({ status: "ok" });
3450+
}
3451+
);
34483452

34493453
store.set(wsClientAtom, {
34503454
sendCommand,
@@ -3577,17 +3581,21 @@ describe("XtermHost", () => {
35773581
status: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected"
35783582
) => void)
35793583
| undefined;
3580-
let connectionStatus: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected" =
3581-
"connected";
3584+
let connectionStatus:
3585+
| "connecting"
3586+
| "connected"
3587+
| "disconnected"
3588+
| "reconnecting"
3589+
| "rejected" = "connected";
35823590
let rejectInitialSnapshot: ((error: Error) => void) | undefined;
35833591
const consoleSpy = vi.spyOn(console, "error").mockImplementation(() => {});
35843592
const sendCommand = vi
35853593
.fn()
35863594
.mockImplementation((op: string, args: { terminalId?: string; lastSeq?: number }) => {
35873595
if (op === "terminal.snapshot") {
35883596
if (
3589-
sendCommand.mock.calls.filter(([calledOp]) => calledOp === "terminal.snapshot").length ===
3590-
1
3597+
sendCommand.mock.calls.filter(([calledOp]) => calledOp === "terminal.snapshot")
3598+
.length === 1
35913599
) {
35923600
return new Promise((_, reject: (error: Error) => void) => {
35933601
rejectInitialSnapshot = reject;
@@ -3611,7 +3619,9 @@ describe("XtermHost", () => {
36113619
if (connectionStatus !== "connected") {
36123620
return Promise.reject(new Error("WebSocket disconnected"));
36133621
}
3614-
throw new Error(`Unexpected replay request after reconnect during initial hydration: ${args.lastSeq}`);
3622+
throw new Error(
3623+
`Unexpected replay request after reconnect during initial hydration: ${args.lastSeq}`
3624+
);
36153625
}
36163626

36173627
return Promise.resolve({ status: "ok" });
@@ -3673,8 +3683,12 @@ describe("XtermHost", () => {
36733683
status: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected"
36743684
) => void)
36753685
| undefined;
3676-
let connectionStatus: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected" =
3677-
"connected";
3686+
let connectionStatus:
3687+
| "connecting"
3688+
| "connected"
3689+
| "disconnected"
3690+
| "reconnecting"
3691+
| "rejected" = "connected";
36783692
let resolveInitialSnapshot: ((payload: TerminalSnapshotPayload) => void) | undefined;
36793693
let snapshotCount = 0;
36803694
let replayCount = 0;
@@ -4102,9 +4116,7 @@ describe("XtermHost", () => {
41024116
| undefined;
41034117
let subscriptionHandler: ((topic: string, payload: unknown, seq: number) => void) | undefined;
41044118
let replayCount = 0;
4105-
let resolveFirstReconnectReplay:
4106-
| ((payload: TerminalReplayPayload) => void)
4107-
| undefined;
4119+
let resolveFirstReconnectReplay: ((payload: TerminalReplayPayload) => void) | undefined;
41084120
const sendCommand = vi
41094121
.fn()
41104122
.mockImplementation((op: string, args: { terminalId?: string; lastSeq?: number }) => {
@@ -4240,9 +4252,7 @@ describe("XtermHost", () => {
42404252
| undefined;
42414253
let subscriptionHandler: ((topic: string, payload: unknown, seq: number) => void) | undefined;
42424254
let replayCount = 0;
4243-
let resolveFirstReconnectReplay:
4244-
| ((payload: TerminalReplayPayload) => void)
4245-
| undefined;
4255+
let resolveFirstReconnectReplay: ((payload: TerminalReplayPayload) => void) | undefined;
42464256
let releaseDelayedBufferedWrite: (() => void) | undefined;
42474257

42484258
mockTerminal.write.mockImplementation((data: Uint8Array | string, callback?: () => void) => {
@@ -4675,8 +4685,12 @@ describe("XtermHost", () => {
46754685
status: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected"
46764686
) => void)
46774687
| undefined;
4678-
let connectionStatus: "connecting" | "connected" | "disconnected" | "reconnecting" | "rejected" =
4679-
"connected";
4688+
let connectionStatus:
4689+
| "connecting"
4690+
| "connected"
4691+
| "disconnected"
4692+
| "reconnecting"
4693+
| "rejected" = "connected";
46804694
let rejectReconnectReplay: ((error: Error) => void) | undefined;
46814695
let replayCount = 0;
46824696
const getStatus = vi.fn(() => connectionStatus);
@@ -4804,8 +4818,8 @@ describe("XtermHost", () => {
48044818
.mockImplementation((op: string, args: { terminalId?: string; lastSeq?: number }) => {
48054819
if (op === "terminal.snapshot") {
48064820
if (
4807-
sendCommand.mock.calls.filter(([calledOp]) => calledOp === "terminal.snapshot").length ===
4808-
1
4821+
sendCommand.mock.calls.filter(([calledOp]) => calledOp === "terminal.snapshot")
4822+
.length === 1
48094823
) {
48104824
return Promise.resolve({
48114825
status: "ok",

0 commit comments

Comments
 (0)