1
+ import { vitest , describe , it , expect , beforeEach } from "vitest"
1
2
import * as vscode from "vscode"
2
3
import * as path from "path"
3
4
import * as fs from "fs/promises"
@@ -6,16 +7,16 @@ import { GlobalFileNames } from "../shared/globalFileNames"
6
7
import { migrateSettings } from "../utils/migrateSettings"
7
8
8
9
// Mock dependencies
9
- jest . mock ( "vscode" )
10
- jest . mock ( "fs/promises" , ( ) => ( {
11
- mkdir : jest . fn ( ) . mockResolvedValue ( undefined ) ,
12
- readFile : jest . fn ( ) ,
13
- writeFile : jest . fn ( ) . mockResolvedValue ( undefined ) ,
14
- rename : jest . fn ( ) . mockResolvedValue ( undefined ) ,
15
- unlink : jest . fn ( ) . mockResolvedValue ( undefined ) ,
10
+ vitest . mock ( "vscode" )
11
+ vitest . mock ( "fs/promises" , ( ) => ( {
12
+ mkdir : vitest . fn ( ) . mockResolvedValue ( undefined ) ,
13
+ readFile : vitest . fn ( ) ,
14
+ writeFile : vitest . fn ( ) . mockResolvedValue ( undefined ) ,
15
+ rename : vitest . fn ( ) . mockResolvedValue ( undefined ) ,
16
+ unlink : vitest . fn ( ) . mockResolvedValue ( undefined ) ,
16
17
} ) )
17
- jest . mock ( "fs" )
18
- jest . mock ( "../utils/fs" )
18
+ vitest . mock ( "fs" )
19
+ vitest . mock ( "../utils/fs" )
19
20
20
21
describe ( "Settings Migration" , ( ) => {
21
22
let mockContext : vscode . ExtensionContext
@@ -33,16 +34,16 @@ describe("Settings Migration", () => {
33
34
const newMcpSettingsPath = path . join ( mockSettingsDir , GlobalFileNames . mcpSettings )
34
35
35
36
beforeEach ( ( ) => {
36
- jest . clearAllMocks ( )
37
+ vitest . clearAllMocks ( )
37
38
38
39
// Mock output channel
39
40
mockOutputChannel = {
40
- appendLine : jest . fn ( ) ,
41
- append : jest . fn ( ) ,
42
- clear : jest . fn ( ) ,
43
- show : jest . fn ( ) ,
44
- hide : jest . fn ( ) ,
45
- dispose : jest . fn ( ) ,
41
+ appendLine : vitest . fn ( ) ,
42
+ append : vitest . fn ( ) ,
43
+ clear : vitest . fn ( ) ,
44
+ show : vitest . fn ( ) ,
45
+ hide : vitest . fn ( ) ,
46
+ dispose : vitest . fn ( ) ,
46
47
} as unknown as vscode . OutputChannel
47
48
48
49
// Mock extension context
@@ -56,13 +57,13 @@ describe("Settings Migration", () => {
56
57
57
58
it ( "should migrate custom modes file if old file exists and new file doesn't" , async ( ) => {
58
59
// Clear all previous mocks to ensure clean test environment
59
- jest . clearAllMocks ( )
60
+ vitest . clearAllMocks ( )
60
61
61
62
// Setup mock for rename function
62
- const mockRename = ( fs . rename as jest . Mock ) . mockResolvedValue ( undefined )
63
+ const mockRename = vitest . mocked ( fs . rename ) . mockResolvedValue ( undefined )
63
64
64
65
// Mock file existence checks - only return true for paths we want to exist
65
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
66
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
66
67
if ( path === mockSettingsDir ) return true
67
68
if ( path === legacyClineCustomModesPath ) return true
68
69
return false // All other paths don't exist, including destination files
@@ -77,13 +78,13 @@ describe("Settings Migration", () => {
77
78
78
79
it ( "should migrate MCP settings file if old file exists and new file doesn't" , async ( ) => {
79
80
// Clear all previous mocks to ensure clean test environment
80
- jest . clearAllMocks ( )
81
+ vitest . clearAllMocks ( )
81
82
82
83
// Setup mock for rename function
83
- const mockRename = ( fs . rename as jest . Mock ) . mockResolvedValue ( undefined )
84
+ const mockRename = vitest . mocked ( fs . rename ) . mockResolvedValue ( undefined )
84
85
85
86
// Ensure the other files don't interfere with this test
86
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
87
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
87
88
if ( path === mockSettingsDir ) return true
88
89
if ( path === legacyMcpSettingsPath ) return true
89
90
if ( path === legacyClineCustomModesPath ) return false // Ensure this file doesn't exist
@@ -100,13 +101,13 @@ describe("Settings Migration", () => {
100
101
101
102
it ( "should not migrate if new file already exists" , async ( ) => {
102
103
// Clear all previous mocks to ensure clean test environment
103
- jest . clearAllMocks ( )
104
+ vitest . clearAllMocks ( )
104
105
105
106
// Setup mock for rename function
106
- const mockRename = ( fs . rename as jest . Mock ) . mockResolvedValue ( undefined )
107
+ const mockRename = vitest . mocked ( fs . rename ) . mockResolvedValue ( undefined )
107
108
108
109
// Mock file existence checks - both source and destination exist
109
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
110
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
110
111
if ( path === mockSettingsDir ) return true
111
112
if ( path === legacyClineCustomModesPath ) return true
112
113
if ( path === legacyCustomModesJson ) return true // Destination already exists
@@ -123,10 +124,10 @@ describe("Settings Migration", () => {
123
124
124
125
it ( "should handle errors gracefully" , async ( ) => {
125
126
// Clear mocks
126
- jest . clearAllMocks ( )
127
+ vitest . clearAllMocks ( )
127
128
128
129
// Mock file existence to throw error
129
- ; ( fileExistsAtPath as jest . Mock ) . mockRejectedValue ( new Error ( "Test error" ) )
130
+ vitest . mocked ( fileExistsAtPath ) . mockRejectedValue ( new Error ( "Test error" ) )
130
131
131
132
await migrateSettings ( mockContext , mockOutputChannel )
132
133
@@ -138,24 +139,24 @@ describe("Settings Migration", () => {
138
139
139
140
it ( "should convert custom_modes.json to YAML format" , async ( ) => {
140
141
// Clear all previous mocks to ensure clean test environment
141
- jest . clearAllMocks ( )
142
+ vitest . clearAllMocks ( )
142
143
143
144
const testJsonContent = JSON . stringify ( { customModes : [ { slug : "test-mode" , name : "Test Mode" } ] } )
144
145
145
146
// Setup mock functions
146
- const mockWrite = ( fs . writeFile as jest . Mock ) . mockResolvedValue ( undefined )
147
- const mockUnlink = ( fs . unlink as jest . Mock ) . mockResolvedValue ( undefined )
147
+ const mockWrite = vitest . mocked ( fs . writeFile ) . mockResolvedValue ( undefined )
148
+ const mockUnlink = vitest . mocked ( fs . unlink ) . mockResolvedValue ( undefined )
148
149
149
150
// Mock file read to return JSON content
150
- ; ( fs . readFile as jest . Mock ) . mockImplementation ( async ( path : any ) => {
151
+ vitest . mocked ( fs . readFile ) . mockImplementation ( async ( path : any ) => {
151
152
if ( path === legacyCustomModesJson ) {
152
153
return testJsonContent
153
154
}
154
155
throw new Error ( "File not found: " + path )
155
156
} )
156
157
157
158
// Isolate this test by making sure only the specific JSON file exists
158
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
159
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
159
160
if ( path === mockSettingsDir ) return true
160
161
if ( path === legacyCustomModesJson ) return true
161
162
if ( path === legacyClineCustomModesPath ) return false
@@ -178,22 +179,22 @@ describe("Settings Migration", () => {
178
179
179
180
it ( "should handle corrupt JSON gracefully" , async ( ) => {
180
181
// Clear all previous mocks to ensure clean test environment
181
- jest . clearAllMocks ( )
182
+ vitest . clearAllMocks ( )
182
183
183
184
// Setup mock functions
184
- const mockWrite = ( fs . writeFile as jest . Mock ) . mockResolvedValue ( undefined )
185
- const mockUnlink = ( fs . unlink as jest . Mock ) . mockResolvedValue ( undefined )
185
+ const mockWrite = vitest . mocked ( fs . writeFile ) . mockResolvedValue ( undefined )
186
+ const mockUnlink = vitest . mocked ( fs . unlink ) . mockResolvedValue ( undefined )
186
187
187
188
// Mock file read to return corrupt JSON
188
- ; ( fs . readFile as jest . Mock ) . mockImplementation ( async ( path : any ) => {
189
+ vitest . mocked ( fs . readFile ) . mockImplementation ( async ( path : any ) => {
189
190
if ( path === legacyCustomModesJson ) {
190
191
return "{ invalid json content" // This will cause an error when parsed
191
192
}
192
193
throw new Error ( "File not found: " + path )
193
194
} )
194
195
195
196
// Isolate this test
196
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
197
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
197
198
if ( path === mockSettingsDir ) return true
198
199
if ( path === legacyCustomModesJson ) return true
199
200
if ( path === legacyClineCustomModesPath ) return false
@@ -215,22 +216,22 @@ describe("Settings Migration", () => {
215
216
216
217
it ( "should skip migration when YAML file already exists" , async ( ) => {
217
218
// Clear all previous mocks to ensure clean test environment
218
- jest . clearAllMocks ( )
219
+ vitest . clearAllMocks ( )
219
220
220
221
// Setup mock functions
221
- const mockWrite = ( fs . writeFile as jest . Mock ) . mockResolvedValue ( undefined )
222
- const mockUnlink = ( fs . unlink as jest . Mock ) . mockResolvedValue ( undefined )
222
+ const mockWrite = vitest . mocked ( fs . writeFile ) . mockResolvedValue ( undefined )
223
+ const mockUnlink = vitest . mocked ( fs . unlink ) . mockResolvedValue ( undefined )
223
224
224
225
// Mock file read
225
- ; ( fs . readFile as jest . Mock ) . mockImplementation ( async ( path : any ) => {
226
+ vitest . mocked ( fs . readFile ) . mockImplementation ( async ( path : any ) => {
226
227
if ( path === legacyCustomModesJson ) {
227
228
return JSON . stringify ( { customModes : [ ] } )
228
229
}
229
230
throw new Error ( "File not found: " + path )
230
231
} )
231
232
232
233
// Mock file existence checks - both source and yaml destination exist
233
- ; ( fileExistsAtPath as jest . Mock ) . mockImplementation ( async ( path : string ) => {
234
+ vitest . mocked ( fileExistsAtPath ) . mockImplementation ( async ( path : string ) => {
234
235
if ( path === mockSettingsDir ) return true
235
236
if ( path === legacyCustomModesJson ) return true
236
237
if ( path === newCustomModesYaml ) return true // YAML already exists
0 commit comments