Skip to content

Commit 8dd4b72

Browse files
committed
Convert insertContentTool tests from Jest to Vitest
1 parent c96bc40 commit 8dd4b72

File tree

1 file changed

+44
-40
lines changed

1 file changed

+44
-40
lines changed

src/core/tools/__tests__/insertContentTool.test.ts renamed to src/core/tools/__tests__/insertContentTool.spec.ts

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
import * as path from "path"
22
import * as fs from "fs/promises"
33

4+
import type { MockedFunction } from "vitest"
5+
46
import { fileExistsAtPath } from "../../../utils/fs"
57
import { ToolUse, ToolResponse } from "../../../shared/tools"
68
import { insertContentTool } from "../insertContentTool"
79

810
// Mock external dependencies
9-
jest.mock("path", () => {
10-
const originalPath = jest.requireActual("path")
11+
vi.mock("path", async () => {
12+
const originalPath = await vi.importActual("path")
1113
return {
1214
...originalPath,
13-
resolve: jest.fn().mockImplementation((...args) => args.join("/")),
15+
resolve: vi.fn().mockImplementation((...args) => args.join("/")),
1416
}
1517
})
1618

17-
jest.mock("fs/promises", () => ({
18-
readFile: jest.fn(),
19-
writeFile: jest.fn(),
19+
vi.mock("fs/promises", () => ({
20+
readFile: vi.fn(),
21+
writeFile: vi.fn(),
2022
}))
2123

22-
jest.mock("delay", () => jest.fn())
24+
vi.mock("delay", () => ({
25+
default: vi.fn(),
26+
}))
2327

24-
jest.mock("../../../utils/fs", () => ({
25-
fileExistsAtPath: jest.fn().mockResolvedValue(false),
28+
vi.mock("../../../utils/fs", () => ({
29+
fileExistsAtPath: vi.fn().mockResolvedValue(false),
2630
}))
2731

28-
jest.mock("../../prompts/responses", () => ({
32+
vi.mock("../../prompts/responses", () => ({
2933
formatResponse: {
30-
toolError: jest.fn((msg) => `Error: ${msg}`),
31-
rooIgnoreError: jest.fn((path) => `Access denied: ${path}`),
32-
createPrettyPatch: jest.fn((_path, original, updated) => `Diff: ${original} -> ${updated}`),
34+
toolError: vi.fn((msg) => `Error: ${msg}`),
35+
rooIgnoreError: vi.fn((path) => `Access denied: ${path}`),
36+
createPrettyPatch: vi.fn((_path, original, updated) => `Diff: ${original} -> ${updated}`),
3337
},
3438
}))
3539

36-
jest.mock("../../../utils/path", () => ({
37-
getReadablePath: jest.fn().mockReturnValue("test/path.txt"),
40+
vi.mock("../../../utils/path", () => ({
41+
getReadablePath: vi.fn().mockReturnValue("test/path.txt"),
3842
}))
3943

40-
jest.mock("../../ignore/RooIgnoreController", () => ({
44+
vi.mock("../../ignore/RooIgnoreController", () => ({
4145
RooIgnoreController: class {
4246
initialize() {
4347
return Promise.resolve()
@@ -52,19 +56,19 @@ describe("insertContentTool", () => {
5256
const testFilePath = "test/file.txt"
5357
const absoluteFilePath = "/test/file.txt"
5458

55-
const mockedFileExistsAtPath = fileExistsAtPath as jest.MockedFunction<typeof fileExistsAtPath>
56-
const mockedFsReadFile = fs.readFile as jest.MockedFunction<typeof fs.readFile>
57-
const mockedPathResolve = path.resolve as jest.MockedFunction<typeof path.resolve>
59+
const mockedFileExistsAtPath = fileExistsAtPath as MockedFunction<typeof fileExistsAtPath>
60+
const mockedFsReadFile = fs.readFile as MockedFunction<typeof fs.readFile>
61+
const mockedPathResolve = path.resolve as MockedFunction<typeof path.resolve>
5862

5963
let mockCline: any
60-
let mockAskApproval: jest.Mock
61-
let mockHandleError: jest.Mock
62-
let mockPushToolResult: jest.Mock
63-
let mockRemoveClosingTag: jest.Mock
64+
let mockAskApproval: ReturnType<typeof vi.fn>
65+
let mockHandleError: ReturnType<typeof vi.fn>
66+
let mockPushToolResult: ReturnType<typeof vi.fn>
67+
let mockRemoveClosingTag: ReturnType<typeof vi.fn>
6468
let toolResult: ToolResponse | undefined
6569

6670
beforeEach(() => {
67-
jest.clearAllMocks()
71+
vi.clearAllMocks()
6872

6973
mockedPathResolve.mockReturnValue(absoluteFilePath)
7074
mockedFileExistsAtPath.mockResolvedValue(true) // Assume file exists by default for insert
@@ -75,23 +79,23 @@ describe("insertContentTool", () => {
7579
consecutiveMistakeCount: 0,
7680
didEditFile: false,
7781
rooIgnoreController: {
78-
validateAccess: jest.fn().mockReturnValue(true),
82+
validateAccess: vi.fn().mockReturnValue(true),
7983
},
8084
diffViewProvider: {
8185
editType: undefined,
8286
isEditing: false,
8387
originalContent: "",
84-
open: jest.fn().mockResolvedValue(undefined),
85-
update: jest.fn().mockResolvedValue(undefined),
86-
reset: jest.fn().mockResolvedValue(undefined),
87-
revertChanges: jest.fn().mockResolvedValue(undefined),
88-
saveChanges: jest.fn().mockResolvedValue({
88+
open: vi.fn().mockResolvedValue(undefined),
89+
update: vi.fn().mockResolvedValue(undefined),
90+
reset: vi.fn().mockResolvedValue(undefined),
91+
revertChanges: vi.fn().mockResolvedValue(undefined),
92+
saveChanges: vi.fn().mockResolvedValue({
8993
newProblemsMessage: "",
9094
userEdits: null,
9195
finalContent: "final content",
9296
}),
93-
scrollToFirstDiff: jest.fn(),
94-
pushToolWriteResult: jest.fn().mockImplementation(async function (
97+
scrollToFirstDiff: vi.fn(),
98+
pushToolWriteResult: vi.fn().mockImplementation(async function (
9599
this: any,
96100
task: any,
97101
cwd: string,
@@ -101,17 +105,17 @@ describe("insertContentTool", () => {
101105
}),
102106
},
103107
fileContextTracker: {
104-
trackFileContext: jest.fn().mockResolvedValue(undefined),
108+
trackFileContext: vi.fn().mockResolvedValue(undefined),
105109
},
106-
say: jest.fn().mockResolvedValue(undefined),
107-
ask: jest.fn().mockResolvedValue({ response: "yesButtonClicked" }), // Default to approval
108-
recordToolError: jest.fn(),
109-
sayAndCreateMissingParamError: jest.fn().mockResolvedValue("Missing param error"),
110+
say: vi.fn().mockResolvedValue(undefined),
111+
ask: vi.fn().mockResolvedValue({ response: "yesButtonClicked" }), // Default to approval
112+
recordToolError: vi.fn(),
113+
sayAndCreateMissingParamError: vi.fn().mockResolvedValue("Missing param error"),
110114
}
111115

112-
mockAskApproval = jest.fn().mockResolvedValue(true)
113-
mockHandleError = jest.fn().mockResolvedValue(undefined)
114-
mockRemoveClosingTag = jest.fn((tag, content) => content)
116+
mockAskApproval = vi.fn().mockResolvedValue(true)
117+
mockHandleError = vi.fn().mockResolvedValue(undefined)
118+
mockRemoveClosingTag = vi.fn((tag, content) => content)
115119

116120
toolResult = undefined
117121
})

0 commit comments

Comments
 (0)