1- import React from "react" ;
21import { render , waitFor } from "@testing-library/react" ;
32import App from "../App" ;
43import { DEFAULT_INSPECTOR_CONFIG } from "../lib/constants" ;
4+ import { InspectorConfig } from "../lib/configurationTypes" ;
5+ import * as configUtils from "../utils/configUtils" ;
56
67// Mock auth dependencies first
78jest . mock ( "@modelcontextprotocol/sdk/client/auth.js" , ( ) => ( {
@@ -24,7 +25,7 @@ jest.mock("../lib/auth", () => ({
2425jest . mock ( "../utils/configUtils" , ( ) => ( {
2526 ...jest . requireActual ( "../utils/configUtils" ) ,
2627 getMCPProxyAddress : jest . fn ( ( ) => "http://localhost:6277" ) ,
27- getMCPProxyAuthToken : jest . fn ( ( config ) => ( {
28+ getMCPProxyAuthToken : jest . fn ( ( config : InspectorConfig ) => ( {
2829 token : config . MCP_PROXY_AUTH_TOKEN . value ,
2930 header : "X-MCP-Proxy-Auth" ,
3031 } ) ) ,
@@ -36,6 +37,11 @@ jest.mock("../utils/configUtils", () => ({
3637 saveInspectorConfig : jest . fn ( ) ,
3738} ) ) ;
3839
40+ // Get references to the mocked functions
41+ const mockGetMCPProxyAuthToken = configUtils . getMCPProxyAuthToken as jest . Mock ;
42+ const mockInitializeInspectorConfig =
43+ configUtils . initializeInspectorConfig as jest . Mock ;
44+
3945// Mock other dependencies
4046jest . mock ( "../lib/hooks/useConnection" , ( ) => ( {
4147 useConnection : ( ) => ( {
@@ -87,10 +93,9 @@ describe("App - Config Endpoint", () => {
8793
8894 afterEach ( ( ) => {
8995 jest . clearAllMocks ( ) ;
90-
96+
9197 // Reset getMCPProxyAuthToken to default behavior
92- const { getMCPProxyAuthToken } = require ( "../utils/configUtils" ) ;
93- getMCPProxyAuthToken . mockImplementation ( ( config ) => ( {
98+ mockGetMCPProxyAuthToken . mockImplementation ( ( config : InspectorConfig ) => ( {
9499 token : config . MCP_PROXY_AUTH_TOKEN . value ,
95100 header : "X-MCP-Proxy-Auth" ,
96101 } ) ) ;
@@ -106,8 +111,7 @@ describe("App - Config Endpoint", () => {
106111 } ;
107112
108113 // Mock initializeInspectorConfig to return our test config
109- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
110- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
114+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
111115
112116 render ( < App /> ) ;
113117
@@ -118,7 +122,7 @@ describe("App - Config Endpoint", () => {
118122 headers : {
119123 "X-MCP-Proxy-Auth" : "Bearer test-proxy-token" ,
120124 } ,
121- }
125+ } ,
122126 ) ;
123127 } ) ;
124128 } ) ;
@@ -133,8 +137,7 @@ describe("App - Config Endpoint", () => {
133137 } ;
134138
135139 // Mock initializeInspectorConfig to return our test config
136- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
137- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
140+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
138141
139142 render ( < App /> ) ;
140143
@@ -143,7 +146,7 @@ describe("App - Config Endpoint", () => {
143146 "http://localhost:6277/config" ,
144147 {
145148 headers : { } ,
146- }
149+ } ,
147150 ) ;
148151 } ) ;
149152 } ) ;
@@ -158,12 +161,11 @@ describe("App - Config Endpoint", () => {
158161 } ;
159162
160163 // Mock to return a custom header name
161- const { getMCPProxyAuthToken, initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
162- getMCPProxyAuthToken . mockReturnValue ( {
164+ mockGetMCPProxyAuthToken . mockReturnValue ( {
163165 token : "test-proxy-token" ,
164166 header : "X-Custom-Auth" ,
165167 } ) ;
166- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
168+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
167169
168170 render ( < App /> ) ;
169171
@@ -174,7 +176,7 @@ describe("App - Config Endpoint", () => {
174176 headers : {
175177 "X-Custom-Auth" : "Bearer test-proxy-token" ,
176178 } ,
177- }
179+ } ,
178180 ) ;
179181 } ) ;
180182 } ) ;
@@ -188,10 +190,9 @@ describe("App - Config Endpoint", () => {
188190 } ,
189191 } ;
190192
191- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
192- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
193+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
193194
194- const { container } = render ( < App /> ) ;
195+ render ( < App /> ) ;
195196
196197 await waitFor ( ( ) => {
197198 expect ( global . fetch ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -204,7 +205,7 @@ describe("App - Config Endpoint", () => {
204205 headers : expect . objectContaining ( {
205206 "X-MCP-Proxy-Auth" : "Bearer test-proxy-token" ,
206207 } ) ,
207- } )
208+ } ) ,
208209 ) ;
209210 } ) ;
210211
@@ -217,8 +218,7 @@ describe("App - Config Endpoint", () => {
217218 } ,
218219 } ;
219220
220- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
221- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
221+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
222222
223223 // Mock fetch to reject
224224 ( global . fetch as jest . Mock ) . mockRejectedValue ( new Error ( "Network error" ) ) ;
@@ -231,10 +231,10 @@ describe("App - Config Endpoint", () => {
231231 await waitFor ( ( ) => {
232232 expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
233233 "Error fetching default environment:" ,
234- expect . any ( Error )
234+ expect . any ( Error ) ,
235235 ) ;
236236 } ) ;
237237
238238 consoleErrorSpy . mockRestore ( ) ;
239239 } ) ;
240- } ) ;
240+ } ) ;
0 commit comments