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

transport.test.ts

78 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { isTransportConnectionErrorMessage, sanitizeThreadErrorMessage } from "./transport.ts";
4​
5describe("isTransportConnectionErrorMessage", () => {
6 it("returns true for SocketCloseError", () => {
7 expect(isTransportConnectionErrorMessage("SocketCloseError: connection reset")).toBe(true);
8 });
9​
10 it("returns true for SocketOpenError", () => {
11 expect(isTransportConnectionErrorMessage("SocketOpenError: ECONNREFUSED")).toBe(true);
12 });
13​
14 it("returns true for React Native disconnected socket errors", () => {
15 expect(
16 isTransportConnectionErrorMessage(
17 "The operation couldn't be completed. Socket is not connected",
18 ),
19 ).toBe(true);
20 });
21​
22 it("recognizes connection errors emitted by the Effect RPC session", () => {
23 expect(isTransportConnectionErrorMessage("Test environment disconnected.")).toBe(true);
24 expect(
25 isTransportConnectionErrorMessage(
26 "Test environment could not establish a WebSocket connection.",
27 ),
28 ).toBe(true);
29 expect(isTransportConnectionErrorMessage("Test environment is not connected.")).toBe(true);
30 expect(isTransportConnectionErrorMessage("ClientProtocolError: socket closed")).toBe(true);
31 });
32​
33 it("returns true for the legacy V12 server WebSocket message", () => {
34 expect(
35 isTransportConnectionErrorMessage("Unable to connect to the V12 server WebSocket."),
36 ).toBe(true);
37 });
38​
39 it("returns true for the V12 server WebSocket message", () => {
40 expect(
41 isTransportConnectionErrorMessage("Unable to connect to the V12 server WebSocket."),
42 ).toBe(true);
43 });
44​
45 it("returns true for ping timeout", () => {
46 expect(isTransportConnectionErrorMessage("ping timeout")).toBe(true);
47 });
48​
49 it("returns false for business logic errors", () => {
50 expect(isTransportConnectionErrorMessage("Thread not found")).toBe(false);
51 expect(isTransportConnectionErrorMessage("Invalid model selection")).toBe(false);
52 });
53​
54 it("returns false for null, undefined, and empty strings", () => {
55 expect(isTransportConnectionErrorMessage(null)).toBe(false);
56 expect(isTransportConnectionErrorMessage(undefined)).toBe(false);
57 expect(isTransportConnectionErrorMessage("")).toBe(false);
58 expect(isTransportConnectionErrorMessage(" ")).toBe(false);
59 });
60});
61​
62describe("sanitizeThreadErrorMessage", () => {
63 it("strips transport errors", () => {
64 expect(sanitizeThreadErrorMessage("SocketCloseError: oops")).toBeNull();
65 });
66​
67 it("preserves non-transport errors", () => {
68 expect(sanitizeThreadErrorMessage("Thread not found")).toBe("Thread not found");
69 expect(sanitizeThreadErrorMessage("Select a base branch before sending.")).toBe(
70 "Select a base branch before sending.",
71 );
72 });
73​
74 it("returns null for null/undefined", () => {
75 expect(sanitizeThreadErrorMessage(null)).toBeNull();
76 expect(sanitizeThreadErrorMessage(undefined)).toBeNull();
77 });
78});