1
- import React from "react" ;
2
1
import { render , waitFor } from "@testing-library/react" ;
3
2
import App from "../App" ;
4
3
import { DEFAULT_INSPECTOR_CONFIG } from "../lib/constants" ;
4
+ import { InspectorConfig } from "../lib/configurationTypes" ;
5
+ import * as configUtils from "../utils/configUtils" ;
5
6
6
7
// Mock auth dependencies first
7
8
jest . mock ( "@modelcontextprotocol/sdk/client/auth.js" , ( ) => ( {
@@ -24,7 +25,7 @@ jest.mock("../lib/auth", () => ({
24
25
jest . mock ( "../utils/configUtils" , ( ) => ( {
25
26
...jest . requireActual ( "../utils/configUtils" ) ,
26
27
getMCPProxyAddress : jest . fn ( ( ) => "http://localhost:6277" ) ,
27
- getMCPProxyAuthToken : jest . fn ( ( config ) => ( {
28
+ getMCPProxyAuthToken : jest . fn ( ( config : InspectorConfig ) => ( {
28
29
token : config . MCP_PROXY_AUTH_TOKEN . value ,
29
30
header : "X-MCP-Proxy-Auth" ,
30
31
} ) ) ,
@@ -36,6 +37,11 @@ jest.mock("../utils/configUtils", () => ({
36
37
saveInspectorConfig : jest . fn ( ) ,
37
38
} ) ) ;
38
39
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
+
39
45
// Mock other dependencies
40
46
jest . mock ( "../lib/hooks/useConnection" , ( ) => ( {
41
47
useConnection : ( ) => ( {
@@ -87,10 +93,9 @@ describe("App - Config Endpoint", () => {
87
93
88
94
afterEach ( ( ) => {
89
95
jest . clearAllMocks ( ) ;
90
-
96
+
91
97
// Reset getMCPProxyAuthToken to default behavior
92
- const { getMCPProxyAuthToken } = require ( "../utils/configUtils" ) ;
93
- getMCPProxyAuthToken . mockImplementation ( ( config ) => ( {
98
+ mockGetMCPProxyAuthToken . mockImplementation ( ( config : InspectorConfig ) => ( {
94
99
token : config . MCP_PROXY_AUTH_TOKEN . value ,
95
100
header : "X-MCP-Proxy-Auth" ,
96
101
} ) ) ;
@@ -106,8 +111,7 @@ describe("App - Config Endpoint", () => {
106
111
} ;
107
112
108
113
// Mock initializeInspectorConfig to return our test config
109
- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
110
- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
114
+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
111
115
112
116
render ( < App /> ) ;
113
117
@@ -118,7 +122,7 @@ describe("App - Config Endpoint", () => {
118
122
headers : {
119
123
"X-MCP-Proxy-Auth" : "Bearer test-proxy-token" ,
120
124
} ,
121
- }
125
+ } ,
122
126
) ;
123
127
} ) ;
124
128
} ) ;
@@ -133,8 +137,7 @@ describe("App - Config Endpoint", () => {
133
137
} ;
134
138
135
139
// Mock initializeInspectorConfig to return our test config
136
- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
137
- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
140
+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
138
141
139
142
render ( < App /> ) ;
140
143
@@ -143,7 +146,7 @@ describe("App - Config Endpoint", () => {
143
146
"http://localhost:6277/config" ,
144
147
{
145
148
headers : { } ,
146
- }
149
+ } ,
147
150
) ;
148
151
} ) ;
149
152
} ) ;
@@ -158,12 +161,11 @@ describe("App - Config Endpoint", () => {
158
161
} ;
159
162
160
163
// Mock to return a custom header name
161
- const { getMCPProxyAuthToken, initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
162
- getMCPProxyAuthToken . mockReturnValue ( {
164
+ mockGetMCPProxyAuthToken . mockReturnValue ( {
163
165
token : "test-proxy-token" ,
164
166
header : "X-Custom-Auth" ,
165
167
} ) ;
166
- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
168
+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
167
169
168
170
render ( < App /> ) ;
169
171
@@ -174,7 +176,7 @@ describe("App - Config Endpoint", () => {
174
176
headers : {
175
177
"X-Custom-Auth" : "Bearer test-proxy-token" ,
176
178
} ,
177
- }
179
+ } ,
178
180
) ;
179
181
} ) ;
180
182
} ) ;
@@ -188,10 +190,9 @@ describe("App - Config Endpoint", () => {
188
190
} ,
189
191
} ;
190
192
191
- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
192
- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
193
+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
193
194
194
- const { container } = render ( < App /> ) ;
195
+ render ( < App /> ) ;
195
196
196
197
await waitFor ( ( ) => {
197
198
expect ( global . fetch ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -204,7 +205,7 @@ describe("App - Config Endpoint", () => {
204
205
headers : expect . objectContaining ( {
205
206
"X-MCP-Proxy-Auth" : "Bearer test-proxy-token" ,
206
207
} ) ,
207
- } )
208
+ } ) ,
208
209
) ;
209
210
} ) ;
210
211
@@ -217,8 +218,7 @@ describe("App - Config Endpoint", () => {
217
218
} ,
218
219
} ;
219
220
220
- const { initializeInspectorConfig } = require ( "../utils/configUtils" ) ;
221
- initializeInspectorConfig . mockReturnValue ( mockConfig ) ;
221
+ mockInitializeInspectorConfig . mockReturnValue ( mockConfig ) ;
222
222
223
223
// Mock fetch to reject
224
224
( global . fetch as jest . Mock ) . mockRejectedValue ( new Error ( "Network error" ) ) ;
@@ -231,10 +231,10 @@ describe("App - Config Endpoint", () => {
231
231
await waitFor ( ( ) => {
232
232
expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
233
233
"Error fetching default environment:" ,
234
- expect . any ( Error )
234
+ expect . any ( Error ) ,
235
235
) ;
236
236
} ) ;
237
237
238
238
consoleErrorSpy . mockRestore ( ) ;
239
239
} ) ;
240
- } ) ;
240
+ } ) ;
0 commit comments