1+ // We use the ClaudeMCPClient as a reference to test the DefaultMCPClient
12import * as fs from 'fs' ;
23import * as path from 'path' ;
34import * as os from 'os' ;
@@ -68,47 +69,47 @@ describe('ClaudeMCPClient', () => {
6869 } ) ;
6970
7071 describe ( 'isClientSupported' , ( ) => {
71- it ( 'should return true for macOS' , ( ) => {
72+ it ( 'should return true for macOS' , async ( ) => {
7273 Object . defineProperty ( process , 'platform' , {
7374 value : 'darwin' ,
7475 writable : true ,
7576 } ) ;
76- expect ( client . isClientSupported ( ) ) . toBe ( true ) ;
77+ await expect ( client . isClientSupported ( ) ) . resolves . toBe ( true ) ;
7778 } ) ;
7879
79- it ( 'should return true for Windows' , ( ) => {
80+ it ( 'should return true for Windows' , async ( ) => {
8081 Object . defineProperty ( process , 'platform' , {
8182 value : 'win32' ,
8283 writable : true ,
8384 } ) ;
84- expect ( client . isClientSupported ( ) ) . toBe ( true ) ;
85+ await expect ( client . isClientSupported ( ) ) . resolves . toBe ( true ) ;
8586 } ) ;
8687
87- it ( 'should return false for Linux' , ( ) => {
88+ it ( 'should return false for Linux' , async ( ) => {
8889 Object . defineProperty ( process , 'platform' , {
8990 value : 'linux' ,
9091 writable : true ,
9192 } ) ;
92- expect ( client . isClientSupported ( ) ) . toBe ( false ) ;
93+ await expect ( client . isClientSupported ( ) ) . resolves . toBe ( false ) ;
9394 } ) ;
9495
95- it ( 'should return false for other platforms' , ( ) => {
96+ it ( 'should return false for other platforms' , async ( ) => {
9697 Object . defineProperty ( process , 'platform' , {
9798 value : 'freebsd' ,
9899 writable : true ,
99100 } ) ;
100- expect ( client . isClientSupported ( ) ) . toBe ( false ) ;
101+ await expect ( client . isClientSupported ( ) ) . resolves . toBe ( false ) ;
101102 } ) ;
102103 } ) ;
103104
104105 describe ( 'getConfigPath' , ( ) => {
105- it ( 'should return correct path for macOS' , ( ) => {
106+ it ( 'should return correct path for macOS' , async ( ) => {
106107 Object . defineProperty ( process , 'platform' , {
107108 value : 'darwin' ,
108109 writable : true ,
109110 } ) ;
110111
111- const configPath = ( client as any ) . getConfigPath ( ) ;
112+ const configPath = await client . getConfigPath ( ) ;
112113 expect ( configPath ) . toBe (
113114 path . join (
114115 mockHomeDir ,
@@ -120,7 +121,7 @@ describe('ClaudeMCPClient', () => {
120121 ) ;
121122 } ) ;
122123
123- it ( 'should return correct path for Windows' , ( ) => {
124+ it ( 'should return correct path for Windows' , async ( ) => {
124125 Object . defineProperty ( process , 'platform' , {
125126 value : 'win32' ,
126127 writable : true ,
@@ -129,19 +130,19 @@ describe('ClaudeMCPClient', () => {
129130 const mockAppData = 'C:\\Users\\Test\\AppData\\Roaming' ;
130131 process . env . APPDATA = mockAppData ;
131132
132- const configPath = ( client as any ) . getConfigPath ( ) ;
133+ const configPath = await client . getConfigPath ( ) ;
133134 expect ( configPath ) . toBe (
134135 path . join ( mockAppData , 'Claude' , 'claude_desktop_config.json' ) ,
135136 ) ;
136137 } ) ;
137138
138- it ( 'should throw error for unsupported platform' , ( ) => {
139+ it ( 'should throw error for unsupported platform' , async ( ) => {
139140 Object . defineProperty ( process , 'platform' , {
140141 value : 'linux' ,
141142 writable : true ,
142143 } ) ;
143144
144- expect ( ( ) => ( client as any ) . getConfigPath ( ) ) . toThrow (
145+ await expect ( client . getConfigPath ( ) ) . rejects . toThrow (
145146 'Unsupported platform: linux' ,
146147 ) ;
147148 } ) ;
@@ -231,6 +232,7 @@ describe('ClaudeMCPClient', () => {
231232 expect ( mkdirMock ) . toHaveBeenCalledWith ( expectedConfigDir , {
232233 recursive : true ,
233234 } ) ;
235+
234236 expect ( writeFileMock ) . toHaveBeenCalledWith (
235237 expectedConfigPath ,
236238 JSON . stringify (
@@ -277,16 +279,35 @@ describe('ClaudeMCPClient', () => {
277279 ) ;
278280 } ) ;
279281
280- it ( 'should create new config when existing config is invalid' , async ( ) => {
282+ it ( 'should not overwrite existing config when it is invalid' , async ( ) => {
281283 existsSyncMock . mockReturnValue ( true ) ;
282- readFileMock . mockResolvedValue ( 'invalid json' ) ;
284+ readFileMock . mockResolvedValue (
285+ JSON . stringify ( {
286+ invalidKey : {
287+ existingServer : {
288+ command : 'existing' ,
289+ args : [ ] ,
290+ env : { } ,
291+ } ,
292+ } ,
293+ x : 'y' ,
294+ } ) ,
295+ ) ;
283296
284297 await client . addServer ( mockApiKey ) ;
285298
286299 expect ( writeFileMock ) . toHaveBeenCalledWith (
287300 expect . any ( String ) ,
288301 JSON . stringify (
289302 {
303+ invalidKey : {
304+ existingServer : {
305+ command : 'existing' ,
306+ args : [ ] ,
307+ env : { } ,
308+ } ,
309+ } ,
310+ x : 'y' ,
290311 mcpServers : {
291312 posthog : mockServerConfig ,
292313 } ,
0 commit comments