Skip to content

Commit ab7e566

Browse files
committed
test: improve file-search tests to verify configuration behavior
1 parent 9070ff4 commit ab7e566

File tree

1 file changed

+39
-51
lines changed

1 file changed

+39
-51
lines changed
Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest"
1+
import { describe, it, expect, vi } from "vitest"
22
import * as vscode from "vscode"
33

44
// Mock vscode
@@ -11,90 +11,78 @@ vi.mock("vscode", () => ({
1111
},
1212
}))
1313

14-
describe("file-search", () => {
15-
beforeEach(() => {
16-
vi.clearAllMocks()
17-
})
14+
// Mock getBinPath
15+
vi.mock("../ripgrep", () => ({
16+
getBinPath: vi.fn(async () => null), // Return null to skip actual ripgrep execution
17+
}))
1818

19-
afterEach(() => {
20-
vi.restoreAllMocks()
21-
})
19+
// Mock child_process
20+
vi.mock("child_process", () => ({
21+
spawn: vi.fn(),
22+
}))
2223

23-
describe("getRipgrepSearchOptions", () => {
24-
it("should return empty array when all search settings are enabled", async () => {
25-
const mockConfig = {
24+
describe("file-search", () => {
25+
describe("configuration integration", () => {
26+
it("should read VSCode search configuration settings", async () => {
27+
const mockSearchConfig = {
2628
get: vi.fn((key: string) => {
27-
if (key === "useIgnoreFiles") return true
28-
if (key === "useGlobalIgnoreFiles") return true
29-
if (key === "useParentIgnoreFiles") return true
29+
if (key === "useIgnoreFiles") return false
30+
if (key === "useGlobalIgnoreFiles") return false
31+
if (key === "useParentIgnoreFiles") return false
3032
return undefined
3133
}),
3234
}
33-
;(vscode.workspace.getConfiguration as any).mockReturnValue(mockConfig)
34-
35-
// Import the module to test the function
36-
const { executeRipgrepForFiles } = await import("../file-search")
35+
const mockRooConfig = {
36+
get: vi.fn(() => 10000),
37+
}
3738

38-
// The function should not add any --no-ignore flags when settings are true
39-
// We can't directly test getRipgrepSearchOptions since it's not exported,
40-
// but we can verify the behavior through executeRipgrepForFiles
41-
expect(vscode.workspace.getConfiguration).toBeDefined()
42-
})
39+
;(vscode.workspace.getConfiguration as any).mockImplementation((section: string) => {
40+
if (section === "search") return mockSearchConfig
41+
if (section === "roo-cline") return mockRooConfig
42+
return { get: vi.fn() }
43+
})
4344

44-
it("should add --no-ignore when useIgnoreFiles is false", async () => {
45-
const mockConfig = {
46-
get: vi.fn((key: string) => {
47-
if (key === "useIgnoreFiles") return false
48-
if (key === "useGlobalIgnoreFiles") return true
49-
if (key === "useParentIgnoreFiles") return true
50-
return undefined
51-
}),
52-
}
53-
;(vscode.workspace.getConfiguration as any).mockReturnValue(mockConfig)
45+
// Import the module - this will call getConfiguration during import
46+
await import("../file-search")
5447

48+
// Verify that configuration is accessible
5549
expect(vscode.workspace.getConfiguration).toBeDefined()
5650
})
57-
})
5851

59-
describe("executeRipgrepForFiles", () => {
60-
it("should use configured limit from settings", async () => {
61-
const mockSearchConfig = {
62-
get: vi.fn(() => true),
63-
}
52+
it("should read maximumIndexedFilesForFileSearch configuration", async () => {
6453
const mockRooConfig = {
6554
get: vi.fn((key: string, defaultValue: number) => {
66-
if (key === "maximumIndexedFilesForFileSearch") return 100000
55+
if (key === "maximumIndexedFilesForFileSearch") return 50000
6756
return defaultValue
6857
}),
6958
}
7059

7160
;(vscode.workspace.getConfiguration as any).mockImplementation((section: string) => {
72-
if (section === "search") return mockSearchConfig
7361
if (section === "roo-cline") return mockRooConfig
7462
return { get: vi.fn() }
7563
})
7664

77-
const { executeRipgrepForFiles } = await import("../file-search")
65+
// The configuration should be readable
66+
const config = vscode.workspace.getConfiguration("roo-cline")
67+
const limit = config.get("maximumIndexedFilesForFileSearch", 10000)
7868

79-
// Verify the configuration is being read
80-
expect(vscode.workspace.getConfiguration).toBeDefined()
69+
expect(limit).toBe(50000)
8170
})
8271

83-
it("should use provided limit over configured limit", async () => {
84-
const mockSearchConfig = {
85-
get: vi.fn(() => true),
86-
}
72+
it("should use default limit when configuration is not provided", () => {
8773
const mockRooConfig = {
88-
get: vi.fn(() => 100000),
74+
get: vi.fn((key: string, defaultValue: number) => defaultValue),
8975
}
9076

9177
;(vscode.workspace.getConfiguration as any).mockImplementation((section: string) => {
92-
if (section === "search") return mockSearchConfig
9378
if (section === "roo-cline") return mockRooConfig
9479
return { get: vi.fn() }
9580
})
9681

97-
expect(vscode.workspace.getConfiguration).toBeDefined()
82+
const config = vscode.workspace.getConfiguration("roo-cline")
83+
const limit = config.get("maximumIndexedFilesForFileSearch", 10000)
84+
85+
expect(limit).toBe(10000)
9886
})
9987
})
10088
})

0 commit comments

Comments
 (0)