Skip to content

Commit 7260cc8

Browse files
committed
fix: ESLint and formatting issues in browser API tests
1 parent 6c7483e commit 7260cc8

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

src/browser/api.test.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,27 @@
66
import { describe, test, expect } from "bun:test";
77

88
// Helper to create a mock fetch that returns a specific response
9-
function createMockFetch(responseData: any) {
10-
return async () => {
11-
return {
9+
function createMockFetch(responseData: unknown) {
10+
return () => {
11+
return Promise.resolve({
1212
ok: true,
13-
json: async () => responseData,
14-
} as Response;
13+
json: () => Promise.resolve(responseData),
14+
} as Response);
1515
};
1616
}
1717

18+
interface InvokeResponse<T> {
19+
success: boolean;
20+
data?: T;
21+
error?: unknown;
22+
}
23+
1824
// Helper to create invokeIPC function with mocked fetch
19-
async function createInvokeIPC(mockFetch: any) {
25+
function createInvokeIPC(
26+
mockFetch: (url: string, init?: RequestInit) => Promise<Response>
27+
): <T>(channel: string, ...args: unknown[]) => Promise<T> {
2028
const API_BASE = "http://localhost:3000";
2129

22-
interface InvokeResponse<T> {
23-
success: boolean;
24-
data?: T;
25-
error?: unknown;
26-
}
27-
2830
async function invokeIPC<T>(channel: string, ...args: unknown[]): Promise<T> {
2931
const response = await mockFetch(`${API_BASE}/ipc/${encodeURIComponent(channel)}`, {
3032
method: "POST",
@@ -64,9 +66,10 @@ describe("Browser API invokeIPC", () => {
6466
error: "fatal: contains modified or untracked files",
6567
});
6668

67-
const invokeIPC = await createInvokeIPC(mockFetch);
69+
const invokeIPC = createInvokeIPC(mockFetch);
6870

6971
// Current behavior: invokeIPC throws on string errors
72+
// eslint-disable-next-line @typescript-eslint/await-thenable
7073
await expect(invokeIPC("WORKSPACE_REMOVE", "test-workspace", { force: false })).rejects.toThrow(
7174
"fatal: contains modified or untracked files"
7275
);
@@ -78,7 +81,7 @@ describe("Browser API invokeIPC", () => {
7881
error: "fatal: contains modified or untracked files",
7982
});
8083

81-
const invokeIPC = await createInvokeIPC(mockFetch);
84+
const invokeIPC = createInvokeIPC(mockFetch);
8285

8386
// Desired behavior: Should return { success: false, error: "..." }
8487
// This test documents what we want - actual implementation test is below
@@ -100,23 +103,24 @@ describe("Browser API invokeIPC", () => {
100103
data: { someData: "value" },
101104
});
102105

103-
const invokeIPC = await createInvokeIPC(mockFetch);
106+
const invokeIPC = createInvokeIPC(mockFetch);
104107

105108
const result = await invokeIPC("WORKSPACE_REMOVE", "test-workspace", { force: true });
106109

107110
expect(result).toEqual({ someData: "value" });
108111
});
109112

110113
test("should throw on HTTP errors", async () => {
111-
const mockFetch = async () => {
112-
return {
114+
const mockFetch = () => {
115+
return Promise.resolve({
113116
ok: false,
114117
status: 500,
115-
} as Response;
118+
} as Response);
116119
};
117120

118-
const invokeIPC = await createInvokeIPC(mockFetch);
121+
const invokeIPC = createInvokeIPC(mockFetch);
119122

123+
// eslint-disable-next-line @typescript-eslint/await-thenable
120124
await expect(invokeIPC("WORKSPACE_REMOVE", "test-workspace", { force: false })).rejects.toThrow(
121125
"HTTP error! status: 500"
122126
);
@@ -134,7 +138,7 @@ describe("Browser API invokeIPC", () => {
134138
error: structuredError,
135139
});
136140

137-
const invokeIPC = await createInvokeIPC(mockFetch);
141+
const invokeIPC = createInvokeIPC(mockFetch);
138142

139143
const result = await invokeIPC("WORKSPACE_SEND_MESSAGE", "test-workspace", {
140144
role: "user",
@@ -148,4 +152,3 @@ describe("Browser API invokeIPC", () => {
148152
});
149153
});
150154
});
151-

0 commit comments

Comments
 (0)