Skip to content

Commit 9089def

Browse files
committed
fix: update test files to use Vitest instead of Jest for LMStudio and Ollama fetchers
1 parent b17853d commit 9089def

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

src/api/providers/fetchers/__tests__/lmstudio.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,29 @@
11
import axios from "axios"
2+
import { vi, describe, it, expect, beforeEach } from "vitest"
23
import { LMStudioClient, LLMInfo } from "@lmstudio/sdk" // LLMInfo is a type
34
import { getLMStudioModels, parseLMStudioModel } from "../lmstudio"
45
import { ModelInfo, lMStudioDefaultModelInfo } from "@roo-code/types" // ModelInfo is a type
56

67
// Mock axios
7-
jest.mock("axios")
8-
const mockedAxios = axios as jest.Mocked<typeof axios>
8+
vi.mock("axios")
9+
const mockedAxios = axios as any
910

1011
// Mock @lmstudio/sdk
11-
const mockListDownloadedModels = jest.fn()
12-
jest.mock("@lmstudio/sdk", () => {
13-
const originalModule = jest.requireActual("@lmstudio/sdk")
12+
const mockListDownloadedModels = vi.fn()
13+
vi.mock("@lmstudio/sdk", () => {
1414
return {
15-
...originalModule,
16-
LMStudioClient: jest.fn().mockImplementation(() => ({
15+
LMStudioClient: vi.fn().mockImplementation(() => ({
1716
system: {
1817
listDownloadedModels: mockListDownloadedModels,
1918
},
2019
})),
2120
}
2221
})
23-
const MockedLMStudioClientConstructor = LMStudioClient as jest.MockedClass<typeof LMStudioClient>
22+
const MockedLMStudioClientConstructor = LMStudioClient as any
2423

2524
describe("LMStudio Fetcher", () => {
2625
beforeEach(() => {
27-
jest.clearAllMocks()
26+
vi.clearAllMocks()
2827
MockedLMStudioClientConstructor.mockClear()
2928
})
3029

@@ -133,7 +132,7 @@ describe("LMStudio Fetcher", () => {
133132
})
134133

135134
it("should return an empty object and log error if axios.get fails with a generic error", async () => {
136-
const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => {})
135+
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
137136
const networkError = new Error("Network connection failed")
138137
mockedAxios.get.mockRejectedValueOnce(networkError)
139138

@@ -151,7 +150,7 @@ describe("LMStudio Fetcher", () => {
151150
})
152151

153152
it("should return an empty object and log info if axios.get fails with ECONNREFUSED", async () => {
154-
const consoleInfoSpy = jest.spyOn(console, "warn").mockImplementation(() => {})
153+
const consoleInfoSpy = vi.spyOn(console, "warn").mockImplementation(() => {})
155154
const econnrefusedError = new Error("Connection refused")
156155
;(econnrefusedError as any).code = "ECONNREFUSED"
157156
mockedAxios.get.mockRejectedValueOnce(econnrefusedError)
@@ -168,7 +167,7 @@ describe("LMStudio Fetcher", () => {
168167
})
169168

170169
it("should return an empty object and log error if listDownloadedModels fails", async () => {
171-
const consoleErrorSpy = jest.spyOn(console, "error").mockImplementation(() => {})
170+
const consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {})
172171
const listError = new Error("LMStudio SDK internal error")
173172

174173
mockedAxios.get.mockResolvedValueOnce({ data: {} })

src/api/providers/fetchers/__tests__/ollama.test.ts

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,35 @@
11
import axios from "axios"
22
import path from "path"
3+
import { vi, describe, it, expect, beforeEach } from "vitest"
34
import { getOllamaModels, parseOllamaModel } from "../ollama"
4-
import * as ollamaModelsData from "./fixtures/ollama-model-details.json"
5+
import ollamaModelsData from "./fixtures/ollama-model-details.json"
56

67
// Mock axios
7-
jest.mock("axios")
8-
const mockedAxios = axios as jest.Mocked<typeof axios>
8+
vi.mock("axios")
9+
const mockedAxios = axios as any
910

1011
describe("Ollama Fetcher", () => {
1112
beforeEach(() => {
12-
jest.clearAllMocks()
13+
vi.clearAllMocks()
1314
})
1415

1516
describe("parseOllamaModel", () => {
16-
const ollamaModels = ollamaModelsData as Record<string, any>
17-
const parsedModel = parseOllamaModel(ollamaModels["qwen3-2to16:latest"])
18-
19-
expect(parsedModel).toEqual({
20-
maxTokens: 40960,
21-
contextWindow: 40960,
22-
supportsImages: false,
23-
supportsComputerUse: false,
24-
supportsPromptCache: true,
25-
inputPrice: 0,
26-
outputPrice: 0,
27-
cacheWritesPrice: 0,
28-
cacheReadsPrice: 0,
29-
description: "Family: qwen3, Context: 40960, Size: 32.8B",
17+
it("should correctly parse Ollama model info", () => {
18+
const modelData = ollamaModelsData["qwen3-2to16:latest"]
19+
const parsedModel = parseOllamaModel(modelData)
20+
21+
expect(parsedModel).toEqual({
22+
maxTokens: 40960,
23+
contextWindow: 40960,
24+
supportsImages: false,
25+
supportsComputerUse: false,
26+
supportsPromptCache: true,
27+
inputPrice: 0,
28+
outputPrice: 0,
29+
cacheWritesPrice: 0,
30+
cacheReadsPrice: 0,
31+
description: "Family: qwen3, Context: 40960, Size: 32.8B",
32+
})
3033
})
3134
})
3235

@@ -98,7 +101,7 @@ describe("Ollama Fetcher", () => {
98101
it("should return an empty list if the initial /api/tags call fails", async () => {
99102
const baseUrl = "http://localhost:11434"
100103
mockedAxios.get.mockRejectedValueOnce(new Error("Network error"))
101-
const consoleInfoSpy = jest.spyOn(console, "error").mockImplementation(() => {}) // Spy and suppress output
104+
const consoleInfoSpy = vi.spyOn(console, "error").mockImplementation(() => {}) // Spy and suppress output
102105

103106
const result = await getOllamaModels(baseUrl)
104107

@@ -110,7 +113,7 @@ describe("Ollama Fetcher", () => {
110113

111114
it("should log an info message and return an empty object on ECONNREFUSED", async () => {
112115
const baseUrl = "http://localhost:11434"
113-
const consoleInfoSpy = jest.spyOn(console, "warn").mockImplementation(() => {}) // Spy and suppress output
116+
const consoleInfoSpy = vi.spyOn(console, "warn").mockImplementation(() => {}) // Spy and suppress output
114117

115118
const econnrefusedError = new Error("Connection refused") as any
116119
econnrefusedError.code = "ECONNREFUSED"

webview-ui/src/utils/__tests__/validate.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ describe("Model Validation Functions", () => {
3636
requesty: {},
3737
unbound: {},
3838
litellm: {},
39+
ollama: {},
40+
lmstudio: {},
3941
}
4042

4143
const allowAllOrganization: OrganizationAllowList = {

0 commit comments

Comments
 (0)