Skip to content

Commit 17988f9

Browse files
committed
test improvements
1 parent 06eb425 commit 17988f9

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/core/diff/strategies/new-unified/__tests__/edit-strategies.test.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { applyContextMatching, applyDMP, applyGitFallback } from "../edit-strategies"
22
import { Hunk } from "../types"
3+
import simpleGit from "simple-git"
4+
5+
jest.mock("simple-git")
36

47
const testCases = [
58
{
@@ -260,6 +263,22 @@ describe("applyDMP", () => {
260263

261264
describe("applyGitFallback", () => {
262265
it("should successfully apply changes using git operations", async () => {
266+
// Mock git operations to simulate success
267+
const mockGit = {
268+
init: jest.fn().mockResolvedValue(undefined),
269+
addConfig: jest.fn().mockResolvedValue(undefined),
270+
add: jest.fn().mockResolvedValue(undefined),
271+
commit: jest.fn().mockResolvedValue({ commit: "mock-commit" }),
272+
raw: jest.fn().mockImplementation(async (args) => {
273+
if (args[0] === "checkout") {
274+
return undefined
275+
}
276+
// On cherry-pick, simulate successful application by not throwing
277+
return undefined
278+
}),
279+
}
280+
;(simpleGit as jest.Mock).mockReturnValue(mockGit)
281+
263282
const hunk = {
264283
changes: [
265284
{ type: "context", content: "line1", indent: "" },
@@ -278,6 +297,16 @@ describe("applyGitFallback", () => {
278297
})
279298

280299
it("should return original content with 0 confidence when changes cannot be applied", async () => {
300+
// Mock git operations to simulate failure
301+
const mockGit = {
302+
init: jest.fn().mockResolvedValue(undefined),
303+
addConfig: jest.fn().mockResolvedValue(undefined),
304+
add: jest.fn().mockResolvedValue(undefined),
305+
commit: jest.fn().mockResolvedValue({ commit: "mock-commit" }),
306+
raw: jest.fn().mockRejectedValue(new Error("Cherry-pick failed")),
307+
}
308+
;(simpleGit as jest.Mock).mockReturnValue(mockGit)
309+
281310
const hunk = {
282311
changes: [
283312
{ type: "context", content: "nonexistent", indent: "" },
@@ -291,5 +320,5 @@ describe("applyGitFallback", () => {
291320
expect(result.result).toEqual(content)
292321
expect(result.confidence).toBe(0)
293322
expect(result.strategy).toBe("git-fallback")
294-
}, 10000)
323+
})
295324
})

0 commit comments

Comments
 (0)