Skip to content

Commit d6cc0aa

Browse files
committed
Revert unit tests back to bun:test (only integration tests use Jest)
1 parent a25d01c commit d6cc0aa

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

src/browser/api.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Tests the invokeIPC function to ensure it behaves consistently with Electron's ipcRenderer.invoke()
44
*/
55

6-
import { describe, test, expect } from "@jest/globals";
6+
import { describe, test, expect } from "bun:test";
77

88
// Helper to create a mock fetch that returns a specific response
99
function createMockFetch(responseData: unknown) {

src/hooks/useReviewState.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* The hook itself is a thin wrapper around usePersistedState with manual testing.
77
*/
88

9-
import { describe, it, expect } from "@jest/globals";
9+
import { describe, it, expect } from "bun:test";
1010
import type { HunkReadState } from "@/types/review";
1111
import { evictOldestReviews } from "./useReviewState";
1212

src/runtime/initHook.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect } from "@jest/globals";
1+
import { describe, it, expect } from "bun:test";
22
import { LineBuffer, createLineBufferedLoggers } from "./initHook";
33
import type { InitLogger } from "./Runtime";
44

src/services/aiService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// These tests would need to be rewritten to work with Bun's test runner
33
// For now, the commandProcessor tests demonstrate our testing approach
44

5-
import { describe, it, expect, beforeEach } from "@jest/globals";
5+
import { describe, it, expect, beforeEach } from "bun:test";
66
import { AIService } from "./aiService";
77
import { HistoryService } from "./historyService";
88
import { PartialService } from "./partialService";

src/services/historyService.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach } from "@jest/globals";
1+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
22
import { HistoryService } from "./historyService";
33
import { Config } from "@/config";
44
import { createCmuxMessage } from "@/types/message";

src/services/initStateManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as fs from "fs/promises";
22
import * as path from "path";
33
import * as os from "os";
4-
import { describe, it, expect, beforeEach, afterEach } from "@jest/globals";
4+
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
55
import { Config } from "@/config";
66
import { InitStateManager } from "./initStateManager";
77
import type { WorkspaceInitEvent } from "@/types/ipc";

src/services/partialService.test.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
2-
import { describe, test, expect, beforeEach, jest } from "@jest/globals";
2+
import { describe, test, expect, beforeEach, mock } from "bun:test";
33
import { PartialService } from "./partialService";
44
import type { HistoryService } from "./historyService";
55
import type { Config } from "@/config";
@@ -9,18 +9,18 @@ import { Ok } from "@/types/result";
99
// Mock Config
1010
const createMockConfig = (): Config => {
1111
return {
12-
getSessionDir: jest.fn((workspaceId: string) => `/tmp/test-sessions/${workspaceId}`),
12+
getSessionDir: mock((workspaceId: string) => `/tmp/test-sessions/${workspaceId}`),
1313
} as unknown as Config;
1414
};
1515

1616
// Mock HistoryService
1717
const createMockHistoryService = (): HistoryService => {
1818
return {
19-
appendToHistory: jest.fn(() => Promise.resolve(Ok(undefined))),
20-
getHistory: jest.fn(() => Promise.resolve(Ok([]))),
21-
updateHistory: jest.fn(() => Promise.resolve(Ok(undefined))),
22-
truncateAfterMessage: jest.fn(() => Promise.resolve(Ok(undefined))),
23-
clearHistory: jest.fn(() => Promise.resolve(Ok(undefined))),
19+
appendToHistory: mock(() => Promise.resolve(Ok(undefined))),
20+
getHistory: mock(() => Promise.resolve(Ok([]))),
21+
updateHistory: mock(() => Promise.resolve(Ok(undefined))),
22+
truncateAfterMessage: mock(() => Promise.resolve(Ok(undefined))),
23+
clearHistory: mock(() => Promise.resolve(Ok(undefined))),
2424
} as unknown as HistoryService;
2525
};
2626

@@ -55,13 +55,13 @@ describe("PartialService - Error Recovery", () => {
5555
};
5656

5757
// Mock readPartial to return errored partial
58-
partialService.readPartial = jest.fn(() => Promise.resolve(erroredPartial));
58+
partialService.readPartial = mock(() => Promise.resolve(erroredPartial));
5959

6060
// Mock deletePartial
61-
partialService.deletePartial = jest.fn(() => Promise.resolve(Ok(undefined)));
61+
partialService.deletePartial = mock(() => Promise.resolve(Ok(undefined)));
6262

6363
// Mock getHistory to return no existing messages
64-
mockHistoryService.getHistory = jest.fn(() => Promise.resolve(Ok([])));
64+
mockHistoryService.getHistory = mock(() => Promise.resolve(Ok([])));
6565

6666
// Call commitToHistory
6767
const result = await partialService.commitToHistory(workspaceId);
@@ -70,7 +70,7 @@ describe("PartialService - Error Recovery", () => {
7070
expect(result.success).toBe(true);
7171

7272
// Should have called appendToHistory with cleaned metadata (no error/errorType)
73-
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof jest.fn>;
73+
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof mock>;
7474
expect(appendToHistory).toHaveBeenCalledTimes(1);
7575
const appendedMessage = appendToHistory.mock.calls[0][1] as CmuxMessage;
7676

@@ -81,7 +81,7 @@ describe("PartialService - Error Recovery", () => {
8181
expect(appendedMessage.metadata?.historySequence).toBe(1);
8282

8383
// Should have deleted the partial after committing
84-
const deletePartial = partialService.deletePartial as ReturnType<typeof jest.fn>;
84+
const deletePartial = partialService.deletePartial as ReturnType<typeof mock>;
8585
expect(deletePartial).toHaveBeenCalledWith(workspaceId);
8686
});
8787

@@ -123,13 +123,13 @@ describe("PartialService - Error Recovery", () => {
123123
};
124124

125125
// Mock readPartial to return errored partial
126-
partialService.readPartial = jest.fn(() => Promise.resolve(erroredPartial));
126+
partialService.readPartial = mock(() => Promise.resolve(erroredPartial));
127127

128128
// Mock deletePartial
129-
partialService.deletePartial = jest.fn(() => Promise.resolve(Ok(undefined)));
129+
partialService.deletePartial = mock(() => Promise.resolve(Ok(undefined)));
130130

131131
// Mock getHistory to return existing placeholder
132-
mockHistoryService.getHistory = jest.fn(() => Promise.resolve(Ok([existingPlaceholder])));
132+
mockHistoryService.getHistory = mock(() => Promise.resolve(Ok([existingPlaceholder])));
133133

134134
// Call commitToHistory
135135
const result = await partialService.commitToHistory(workspaceId);
@@ -138,8 +138,8 @@ describe("PartialService - Error Recovery", () => {
138138
expect(result.success).toBe(true);
139139

140140
// Should have called updateHistory (not append) with cleaned metadata
141-
const updateHistory = mockHistoryService.updateHistory as ReturnType<typeof jest.fn>;
142-
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof jest.fn>;
141+
const updateHistory = mockHistoryService.updateHistory as ReturnType<typeof mock>;
142+
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof mock>;
143143
expect(updateHistory).toHaveBeenCalledTimes(1);
144144
expect(appendToHistory).not.toHaveBeenCalled();
145145

@@ -150,7 +150,7 @@ describe("PartialService - Error Recovery", () => {
150150
expect(updatedMessage.metadata?.errorType).toBeUndefined();
151151

152152
// Should have deleted the partial after updating
153-
const deletePartial = partialService.deletePartial as ReturnType<typeof jest.fn>;
153+
const deletePartial = partialService.deletePartial as ReturnType<typeof mock>;
154154
expect(deletePartial).toHaveBeenCalledWith(workspaceId);
155155
});
156156

@@ -171,13 +171,13 @@ describe("PartialService - Error Recovery", () => {
171171
};
172172

173173
// Mock readPartial to return empty errored partial
174-
partialService.readPartial = jest.fn(() => Promise.resolve(emptyErrorPartial));
174+
partialService.readPartial = mock(() => Promise.resolve(emptyErrorPartial));
175175

176176
// Mock deletePartial
177-
partialService.deletePartial = jest.fn(() => Promise.resolve(Ok(undefined)));
177+
partialService.deletePartial = mock(() => Promise.resolve(Ok(undefined)));
178178

179179
// Mock getHistory to return no existing messages
180-
mockHistoryService.getHistory = jest.fn(() => Promise.resolve(Ok([])));
180+
mockHistoryService.getHistory = mock(() => Promise.resolve(Ok([])));
181181

182182
// Call commitToHistory
183183
const result = await partialService.commitToHistory(workspaceId);
@@ -186,11 +186,11 @@ describe("PartialService - Error Recovery", () => {
186186
expect(result.success).toBe(true);
187187

188188
// Should NOT call appendToHistory for empty message (no value to preserve)
189-
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof jest.fn>;
189+
const appendToHistory = mockHistoryService.appendToHistory as ReturnType<typeof mock>;
190190
expect(appendToHistory).not.toHaveBeenCalled();
191191

192192
// Should still delete the partial (cleanup)
193-
const deletePartial = partialService.deletePartial as ReturnType<typeof jest.fn>;
193+
const deletePartial = partialService.deletePartial as ReturnType<typeof mock>;
194194
expect(deletePartial).toHaveBeenCalledWith(workspaceId);
195195
});
196196
});

src/services/streamManager.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, beforeEach, jest } from "@jest/globals";
1+
import { describe, test, expect, beforeEach, mock } from "bun:test";
22
import { StreamManager } from "./streamManager";
33
import type { HistoryService } from "./historyService";
44
import type { PartialService } from "./partialService";
@@ -17,21 +17,21 @@ if (shouldRunIntegrationTests()) {
1717
// Mock HistoryService
1818
const createMockHistoryService = (): HistoryService => {
1919
return {
20-
appendToHistory: jest.fn(() => Promise.resolve({ success: true })),
21-
getHistory: jest.fn(() => Promise.resolve({ success: true, data: [] })),
22-
updateHistory: jest.fn(() => Promise.resolve({ success: true })),
23-
truncateAfterMessage: jest.fn(() => Promise.resolve({ success: true })),
24-
clearHistory: jest.fn(() => Promise.resolve({ success: true })),
20+
appendToHistory: mock(() => Promise.resolve({ success: true })),
21+
getHistory: mock(() => Promise.resolve({ success: true, data: [] })),
22+
updateHistory: mock(() => Promise.resolve({ success: true })),
23+
truncateAfterMessage: mock(() => Promise.resolve({ success: true })),
24+
clearHistory: mock(() => Promise.resolve({ success: true })),
2525
} as unknown as HistoryService;
2626
};
2727

2828
// Mock PartialService
2929
const createMockPartialService = (): PartialService => {
3030
return {
31-
writePartial: jest.fn(() => Promise.resolve({ success: true })),
32-
readPartial: jest.fn(() => Promise.resolve(null)),
33-
deletePartial: jest.fn(() => Promise.resolve({ success: true })),
34-
commitToHistory: jest.fn(() => Promise.resolve({ success: true })),
31+
writePartial: mock(() => Promise.resolve({ success: true })),
32+
readPartial: mock(() => Promise.resolve(null)),
33+
deletePartial: mock(() => Promise.resolve({ success: true })),
34+
commitToHistory: mock(() => Promise.resolve({ success: true })),
3535
} as unknown as PartialService;
3636
};
3737

src/services/systemMessage.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import * as os from "os";
33
import * as path from "path";
44
import { buildSystemMessage } from "./systemMessage";
55
import type { WorkspaceMetadata } from "@/types/workspace";
6-
import { describe, test, expect, beforeEach, afterEach, jest } from "@jest/globals";
6+
import { describe, test, expect, beforeEach, afterEach, spyOn, type Mock } from "bun:test";
77
import { LocalRuntime } from "@/runtime/LocalRuntime";
88

99
describe("buildSystemMessage", () => {
1010
let tempDir: string;
1111
let projectDir: string;
1212
let workspaceDir: string;
1313
let globalDir: string;
14-
let mockHomedir: jest.SpiedFunction<typeof os.homedir>;
14+
let mockHomedir: Mock<typeof os.homedir>;
1515
let runtime: LocalRuntime;
1616

1717
beforeEach(async () => {
@@ -25,7 +25,7 @@ describe("buildSystemMessage", () => {
2525
await fs.mkdir(globalDir, { recursive: true });
2626

2727
// Mock homedir to return our test directory (getSystemDirectory will append .cmux)
28-
mockHomedir = jest.spyOn(os, "homedir");
28+
mockHomedir = spyOn(os, "homedir");
2929
mockHomedir.mockReturnValue(tempDir);
3030

3131
// Create a local runtime for tests

src/stores/MapStore.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, test, expect, beforeEach } from "@jest/globals";
1+
import { describe, test, expect, beforeEach } from "bun:test";
22
import { MapStore } from "./MapStore";
33

44
describe("MapStore", () => {

0 commit comments

Comments
 (0)