(options: MountHookOptions)
| 54 | }>; |
| 55 | |
| 56 | function 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 | |
| 88 | describe("useAgentLogs", () => { |
| 89 | it("Automatically sorts logs that are received out of order", async () => { |
no test coverage detected