Skip to content

Commit 366b34a

Browse files
committed
fix(vitest4): migrate tests and configs for vitest 4 compatibility
1 parent 1176fa0 commit 366b34a

30 files changed

Lines changed: 111 additions & 110 deletions

apps/cli/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "@roo-code/config-typescript/base.json",
33
"compilerOptions": {
4-
"types": ["vitest/globals"],
54
"outDir": "dist",
65
"jsx": "react-jsx",
76
"jsxImportSource": "react",

apps/vscode-e2e/tsconfig.esm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "@roo-code/config-typescript/base.json",
33
"compilerOptions": {
4-
"outDir": "out"
4+
"outDir": "out",
5+
"types": ["node"]
56
},
67
"include": ["src"],
78
"exclude": ["node_modules"]

packages/build/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "@roo-code/config-typescript/base.json",
33
"compilerOptions": {
4-
"types": ["vitest/globals"],
54
"outDir": "dist"
65
},
76
"include": ["src"],

packages/cloud/src/__mocks__/vscode.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22

3-
export const window = {
3+
export const window: { showInformationMessage: (...args: any[]) => any; showErrorMessage: (...args: any[]) => any } = {
44
showInformationMessage: vi.fn(),
55
showErrorMessage: vi.fn(),
66
}
77

8-
export const env = {
8+
export const env: { openExternal: (...args: any[]) => any } = {
99
openExternal: vi.fn(),
1010
}
1111

1212
export const Uri = {
1313
parse: vi.fn((uri: string) => ({ toString: () => uri })),
1414
}
1515

16-
export const commands = {
16+
export const commands: { executeCommand: (...args: any[]) => any } = {
1717
executeCommand: vi.fn().mockResolvedValue(undefined),
1818
}
1919

packages/cloud/src/__tests__/CloudService.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,21 @@ describe("CloudService", () => {
147147
backfillMessages: vi.fn().mockResolvedValue(undefined),
148148
}
149149

150-
vi.mocked(WebAuthService).mockImplementation(() => mockAuthService as unknown as WebAuthService)
150+
vi.mocked(WebAuthService).mockImplementation(function () {
151+
return mockAuthService as unknown as WebAuthService
152+
})
151153

152-
vi.mocked(CloudSettingsService).mockImplementation(() => mockSettingsService as unknown as CloudSettingsService)
154+
vi.mocked(CloudSettingsService).mockImplementation(function () {
155+
return mockSettingsService as unknown as CloudSettingsService
156+
})
153157

154-
vi.mocked(CloudShareService).mockImplementation(() => mockShareService as unknown as CloudShareService)
158+
vi.mocked(CloudShareService).mockImplementation(function () {
159+
return mockShareService as unknown as CloudShareService
160+
})
155161

156-
vi.mocked(TelemetryClient).mockImplementation(() => mockTelemetryClient as unknown as TelemetryClient)
162+
vi.mocked(TelemetryClient).mockImplementation(function () {
163+
return mockTelemetryClient as unknown as TelemetryClient
164+
})
157165
})
158166

159167
afterEach(() => {
@@ -417,7 +425,9 @@ describe("CloudService", () => {
417425
})
418426

419427
// Override the mock to return our properly typed instance
420-
vi.mocked(CloudSettingsService).mockImplementation(() => mockCloudSettingsService)
428+
vi.mocked(CloudSettingsService).mockImplementation(function () {
429+
return mockCloudSettingsService
430+
})
421431

422432
const cloudService = await CloudService.createInstance(mockContext)
423433

@@ -450,9 +460,9 @@ describe("CloudService", () => {
450460
}
451461

452462
// Override the mock to return a service that won't pass instanceof check
453-
vi.mocked(CloudSettingsService).mockImplementation(
454-
() => mockStaticSettingsService as unknown as CloudSettingsService,
455-
)
463+
vi.mocked(CloudSettingsService).mockImplementation(function () {
464+
return mockStaticSettingsService as unknown as CloudSettingsService
465+
})
456466

457467
// This should not throw even though the service doesn't pass instanceof check
458468
const _cloudService = await CloudService.createInstance(mockContext)

packages/cloud/src/__tests__/CloudSettingsService.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ vi.mock("../config", () => ({
1111
getRooCodeApiUrl: vi.fn().mockReturnValue("https://app.roocode.com"),
1212
}))
1313

14-
global.fetch = vi.fn()
14+
global.fetch = vi.fn() as unknown as typeof fetch
1515

1616
describe("CloudSettingsService", () => {
1717
let mockContext: ExtensionContext
@@ -27,7 +27,7 @@ describe("CloudSettingsService", () => {
2727
stop: ReturnType<typeof vi.fn>
2828
}
2929
let cloudSettingsService: CloudSettingsService
30-
let mockLog: ReturnType<typeof vi.fn>
30+
let mockLog: (...args: unknown[]) => void
3131

3232
const mockSettings: OrganizationSettings = {
3333
version: 1,
@@ -75,7 +75,9 @@ describe("CloudSettingsService", () => {
7575
mockLog = vi.fn()
7676

7777
// Mock RefreshTimer constructor
78-
vi.mocked(RefreshTimer).mockImplementation(() => mockRefreshTimer as unknown as RefreshTimer)
78+
vi.mocked(RefreshTimer).mockImplementation(function () {
79+
return mockRefreshTimer as unknown as RefreshTimer
80+
})
7981

8082
cloudSettingsService = new CloudSettingsService(mockContext, mockAuthService as unknown as AuthService, mockLog)
8183
})

packages/cloud/src/__tests__/WebAuthService.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ describe("WebAuthService", () => {
9797
reset: vi.fn(),
9898
}
9999
const MockedRefreshTimer = vi.mocked(RefreshTimer)
100-
MockedRefreshTimer.mockImplementation(() => mockTimer as unknown as RefreshTimer)
100+
MockedRefreshTimer.mockImplementation(function () {
101+
return mockTimer as unknown as RefreshTimer
102+
})
101103

102104
// Setup config mocks - use production URL by default to maintain existing test behavior
103105
vi.mocked(getClerkBaseUrl).mockReturnValue("https://clerk.roocode.com")

packages/cloud/src/retry-queue/__tests__/RetryQueue.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe("RetryQueue", () => {
303303
beforeEach(() => {
304304
// Mock global fetch
305305
fetchMock = vi.fn()
306-
global.fetch = fetchMock
306+
global.fetch = fetchMock as unknown as typeof fetch
307307
})
308308

309309
afterEach(() => {

packages/cloud/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"extends": "@roo-code/config-typescript/base.json",
33
"compilerOptions": {
4-
"types": ["vitest/globals", "node"],
54
"outDir": "./dist"
65
},
76
"include": ["src", "scripts", "*.config.ts"],

packages/config-typescript/base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
"skipLibCheck": true,
1616
"strict": true,
1717
"target": "ES2022",
18-
"types": ["node"]
18+
"types": ["node", "vitest/globals"]
1919
}
2020
}

0 commit comments

Comments
 (0)