MCPcopy Index your code
hub / github.com/coder/coder / mountHook

Function mountHook

site/src/modules/resources/useAgentLogs.test.ts:56–86  ·  view source on GitHub ↗
(options: MountHookOptions)

Source from the content-addressed store, hash-verified

54}>;
55
56function mountHook(options: MountHookOptions): MountHookResult {
57 const { initialAgentId, enabled = true } = options;
58 const serverResult: ServerResult = { current: undefined };
59
60 vi.spyOn(apiModule, "watchWorkspaceAgentLogs").mockImplementation(
61 (agentId, params) => {
62 return new OneWayWebSocket({
63 apiRoute: `/api/v2/workspaceagents/${agentId}/logs`,
64 searchParams: new URLSearchParams({
65 follow: "true",
66 after: params?.after?.toString() || "0",
67 }),
68 websocketInit: (url) => {
69 const [mockSocket, mockServer] = createMockWebSocket(url);
70 serverResult.current = mockServer;
71 return mockSocket;
72 },
73 });
74 },
75 );
76
77 void vi.spyOn(console, "error").mockImplementation(() => {});
78 const toastError = vi.spyOn(toast, "error");
79
80 const { result: hookResult, rerender } = renderHook(
81 (props) => useAgentLogs(props),
82 { initialProps: { enabled, agentId: initialAgentId } },
83 );
84
85 return { rerender, serverResult, hookResult, toastError };
86}
87
88describe("useAgentLogs", () => {
89 it("Automatically sorts logs that are received out of order", async () => {

Callers 1

Calls 2

createMockWebSocketFunction · 0.90
useAgentLogsFunction · 0.90

Tested by

no test coverage detected