@@ -32,13 +32,13 @@ vi.mock("fs/promises")
3232vi . mock ( "../../../core/webview/ClineProvider" )
3333
3434// Mock the MCP SDK modules
35- jest . mock ( "@modelcontextprotocol/sdk/client/stdio" , ( ) => ( {
36- StdioClientTransport : jest . fn ( ) ,
37- getDefaultEnvironment : jest . fn ( ) . mockReturnValue ( { PATH : "/usr/bin" } ) ,
35+ vi . mock ( "@modelcontextprotocol/sdk/client/stdio.js " , ( ) => ( {
36+ StdioClientTransport : vi . fn ( ) ,
37+ getDefaultEnvironment : vi . fn ( ) . mockReturnValue ( { PATH : "/usr/bin" } ) ,
3838} ) )
3939
40- jest . mock ( "@modelcontextprotocol/sdk/client/index" , ( ) => ( {
41- Client : jest . fn ( ) ,
40+ vi . mock ( "@modelcontextprotocol/sdk/client/index.js " , ( ) => ( {
41+ Client : vi . fn ( ) ,
4242} ) )
4343
4444describe ( "McpHub" , ( ) => {
@@ -699,16 +699,18 @@ describe("McpHub", () => {
699699 } )
700700
701701 describe ( "Windows command wrapping" , ( ) => {
702- let StdioClientTransport : jest . Mock
703- let Client : jest . Mock
702+ let StdioClientTransport : ReturnType < typeof vi . fn >
703+ let Client : ReturnType < typeof vi . fn >
704704
705- beforeEach ( ( ) => {
705+ beforeEach ( async ( ) => {
706706 // Reset mocks
707- jest . clearAllMocks ( )
707+ vi . clearAllMocks ( )
708708
709709 // Get references to the mocked constructors
710- StdioClientTransport = require ( "@modelcontextprotocol/sdk/client/stdio" ) . StdioClientTransport as jest . Mock
711- Client = require ( "@modelcontextprotocol/sdk/client/index" ) . Client as jest . Mock
710+ const stdioModule = await import ( "@modelcontextprotocol/sdk/client/stdio.js" )
711+ const clientModule = await import ( "@modelcontextprotocol/sdk/client/index.js" )
712+ StdioClientTransport = stdioModule . StdioClientTransport as ReturnType < typeof vi . fn >
713+ Client = clientModule . Client as ReturnType < typeof vi . fn >
712714
713715 // Mock Windows platform
714716 Object . defineProperty ( process , "platform" , {
@@ -722,10 +724,10 @@ describe("McpHub", () => {
722724 it ( "should wrap commands with cmd.exe on Windows" , async ( ) => {
723725 // Mock StdioClientTransport
724726 const mockTransport = {
725- start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
726- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
727+ start : vi . fn ( ) . mockResolvedValue ( undefined ) ,
728+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
727729 stderr : {
728- on : jest . fn ( ) ,
730+ on : vi . fn ( ) ,
729731 } ,
730732 onerror : null ,
731733 onclose : null ,
@@ -746,17 +748,17 @@ describe("McpHub", () => {
746748
747749 // Mock Client
748750 Client . mockImplementation ( ( ) => ( {
749- connect : jest . fn ( ) . mockResolvedValue ( undefined ) ,
750- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
751- getInstructions : jest . fn ( ) . mockReturnValue ( "test instructions" ) ,
752- request : jest . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
751+ connect : vi . fn ( ) . mockResolvedValue ( undefined ) ,
752+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
753+ getInstructions : vi . fn ( ) . mockReturnValue ( "test instructions" ) ,
754+ request : vi . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
753755 } ) )
754756
755757 // Create a new McpHub instance
756758 const mcpHub = new McpHub ( mockProvider as ClineProvider )
757759
758760 // Mock the config file read
759- ; ( fs . readFile as jest . Mock ) . mockResolvedValue (
761+ vi . mocked ( fs . readFile ) . mockResolvedValue (
760762 JSON . stringify ( {
761763 mcpServers : {
762764 "test-npx-server" : {
@@ -790,10 +792,10 @@ describe("McpHub", () => {
790792
791793 // Mock StdioClientTransport
792794 const mockTransport = {
793- start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
794- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
795+ start : vi . fn ( ) . mockResolvedValue ( undefined ) ,
796+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
795797 stderr : {
796- on : jest . fn ( ) ,
798+ on : vi . fn ( ) ,
797799 } ,
798800 onerror : null ,
799801 onclose : null ,
@@ -808,17 +810,17 @@ describe("McpHub", () => {
808810
809811 // Mock Client
810812 Client . mockImplementation ( ( ) => ( {
811- connect : jest . fn ( ) . mockResolvedValue ( undefined ) ,
812- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
813- getInstructions : jest . fn ( ) . mockReturnValue ( "test instructions" ) ,
814- request : jest . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
813+ connect : vi . fn ( ) . mockResolvedValue ( undefined ) ,
814+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
815+ getInstructions : vi . fn ( ) . mockReturnValue ( "test instructions" ) ,
816+ request : vi . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
815817 } ) )
816818
817819 // Create a new McpHub instance
818820 const mcpHub = new McpHub ( mockProvider as ClineProvider )
819821
820822 // Mock the config file read
821- ; ( fs . readFile as jest . Mock ) . mockResolvedValue (
823+ vi . mocked ( fs . readFile ) . mockResolvedValue (
822824 JSON . stringify ( {
823825 mcpServers : {
824826 "test-npx-server" : {
@@ -852,10 +854,10 @@ describe("McpHub", () => {
852854
853855 // Mock StdioClientTransport
854856 const mockTransport = {
855- start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
856- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
857+ start : vi . fn ( ) . mockResolvedValue ( undefined ) ,
858+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
857859 stderr : {
858- on : jest . fn ( ) ,
860+ on : vi . fn ( ) ,
859861 } ,
860862 onerror : null ,
861863 onclose : null ,
@@ -870,17 +872,17 @@ describe("McpHub", () => {
870872
871873 // Mock Client
872874 Client . mockImplementation ( ( ) => ( {
873- connect : jest . fn ( ) . mockResolvedValue ( undefined ) ,
874- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
875- getInstructions : jest . fn ( ) . mockReturnValue ( "test instructions" ) ,
876- request : jest . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
875+ connect : vi . fn ( ) . mockResolvedValue ( undefined ) ,
876+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
877+ getInstructions : vi . fn ( ) . mockReturnValue ( "test instructions" ) ,
878+ request : vi . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
877879 } ) )
878880
879881 // Create a new McpHub instance
880882 const mcpHub = new McpHub ( mockProvider as ClineProvider )
881883
882884 // Mock the config file read with cmd.exe already as command
883- ; ( fs . readFile as jest . Mock ) . mockResolvedValue (
885+ vi . mocked ( fs . readFile ) . mockResolvedValue (
884886 JSON . stringify ( {
885887 mcpServers : {
886888 "test-cmd-server" : {
@@ -914,10 +916,10 @@ describe("McpHub", () => {
914916
915917 // Mock StdioClientTransport to simulate the ENOENT error without wrapping
916918 const mockTransport = {
917- start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
918- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
919+ start : vi . fn ( ) . mockResolvedValue ( undefined ) ,
920+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
919921 stderr : {
920- on : jest . fn ( ) ,
922+ on : vi . fn ( ) ,
921923 } ,
922924 onerror : null ,
923925 onclose : null ,
@@ -939,17 +941,17 @@ describe("McpHub", () => {
939941
940942 // Mock Client
941943 Client . mockImplementation ( ( ) => ( {
942- connect : jest . fn ( ) . mockResolvedValue ( undefined ) ,
943- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
944- getInstructions : jest . fn ( ) . mockReturnValue ( "test instructions" ) ,
945- request : jest . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
944+ connect : vi . fn ( ) . mockResolvedValue ( undefined ) ,
945+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
946+ getInstructions : vi . fn ( ) . mockReturnValue ( "test instructions" ) ,
947+ request : vi . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
946948 } ) )
947949
948950 // Create a new McpHub instance
949951 const mcpHub = new McpHub ( mockProvider as ClineProvider )
950952
951953 // Mock the config file read - simulating fnm/nvm-windows scenario
952- ; ( fs . readFile as jest . Mock ) . mockResolvedValue (
954+ vi . mocked ( fs . readFile ) . mockResolvedValue (
953955 JSON . stringify ( {
954956 mcpServers : {
955957 "test-fnm-npx-server" : {
@@ -994,10 +996,10 @@ describe("McpHub", () => {
994996
995997 // Mock StdioClientTransport
996998 const mockTransport = {
997- start : jest . fn ( ) . mockResolvedValue ( undefined ) ,
998- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
999+ start : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1000+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
9991001 stderr : {
1000- on : jest . fn ( ) ,
1002+ on : vi . fn ( ) ,
10011003 } ,
10021004 onerror : null ,
10031005 onclose : null ,
@@ -1012,17 +1014,17 @@ describe("McpHub", () => {
10121014
10131015 // Mock Client
10141016 Client . mockImplementation ( ( ) => ( {
1015- connect : jest . fn ( ) . mockResolvedValue ( undefined ) ,
1016- close : jest . fn ( ) . mockResolvedValue ( undefined ) ,
1017- getInstructions : jest . fn ( ) . mockReturnValue ( "test instructions" ) ,
1018- request : jest . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
1017+ connect : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1018+ close : vi . fn ( ) . mockResolvedValue ( undefined ) ,
1019+ getInstructions : vi . fn ( ) . mockReturnValue ( "test instructions" ) ,
1020+ request : vi . fn ( ) . mockResolvedValue ( { tools : [ ] , resources : [ ] , resourceTemplates : [ ] } ) ,
10191021 } ) )
10201022
10211023 // Create a new McpHub instance
10221024 const mcpHub = new McpHub ( mockProvider as ClineProvider )
10231025
10241026 // Mock the config file read with CMD (uppercase) as command
1025- ; ( fs . readFile as jest . Mock ) . mockResolvedValue (
1027+ vi . mocked ( fs . readFile ) . mockResolvedValue (
10261028 JSON . stringify ( {
10271029 mcpServers : {
10281030 "test-cmd-uppercase-server" : {
0 commit comments