Skip to content

Commit 760c7e4

Browse files
fix: replace require() imports with ES modules in tests
- Replaced all require() imports with proper ES module imports - Fixed ESLint @typescript-eslint/no-require-imports errors - Removed unused variable mockGetMCPProxyAddress - Added proper TypeScript types instead of 'any' - All tests passing and linting clean 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 62402b4 commit 760c7e4

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

client/src/App.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,10 @@ const App = () => {
347347

348348
useEffect(() => {
349349
const headers: HeadersInit = {};
350-
const proxyAuthToken = getMCPProxyAuthToken(config);
350+
const { token: proxyAuthToken, header: proxyAuthTokenHeader } =
351+
getMCPProxyAuthToken(config);
351352
if (proxyAuthToken) {
352-
headers["Authorization"] = `Bearer ${proxyAuthToken}`;
353+
headers[proxyAuthTokenHeader] = `Bearer ${proxyAuthToken}`;
353354
}
354355

355356
fetch(`${getMCPProxyAddress(config)}/config`, { headers })

client/src/__tests__/App.config.test.tsx

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from "react";
21
import { render, waitFor } from "@testing-library/react";
32
import App from "../App";
43
import { 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
78
jest.mock("@modelcontextprotocol/sdk/client/auth.js", () => ({
@@ -24,7 +25,7 @@ jest.mock("../lib/auth", () => ({
2425
jest.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
4046
jest.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+
});

client/src/lib/hooks/useConnection.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ export function useConnection({
243243
const checkProxyHealth = async () => {
244244
try {
245245
const proxyHealthUrl = new URL(`${getMCPProxyAddress(config)}/health`);
246-
const proxyAuthToken = getMCPProxyAuthToken(config);
246+
const { token: proxyAuthToken, header: proxyAuthTokenHeader } =
247+
getMCPProxyAuthToken(config);
247248
const headers: HeadersInit = {};
248249
if (proxyAuthToken) {
249-
headers["X-MCP-Proxy-Auth"] = `Bearer ${proxyAuthToken}`;
250+
headers[proxyAuthTokenHeader] = `Bearer ${proxyAuthToken}`;
250251
}
251252
const proxyHealthResponse = await fetch(proxyHealthUrl, { headers });
252253
const proxyHealth = await proxyHealthResponse.json();
@@ -332,10 +333,11 @@ export function useConnection({
332333
}
333334

334335
// Add proxy authentication
335-
const proxyAuthToken = getMCPProxyAuthToken(config);
336+
const { token: proxyAuthToken, header: proxyAuthTokenHeader } =
337+
getMCPProxyAuthToken(config);
336338
const proxyHeaders: HeadersInit = {};
337339
if (proxyAuthToken) {
338-
proxyHeaders["X-MCP-Proxy-Auth"] = `Bearer ${proxyAuthToken}`;
340+
proxyHeaders[proxyAuthTokenHeader] = `Bearer ${proxyAuthToken}`;
339341
}
340342

341343
// Create appropriate transport

client/src/utils/__tests__/configUtils.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe("configUtils", () => {
5757
...DEFAULT_INSPECTOR_CONFIG,
5858
MCP_PROXY_AUTH_TOKEN: {
5959
...DEFAULT_INSPECTOR_CONFIG.MCP_PROXY_AUTH_TOKEN,
60-
value: null as any,
60+
value: null as unknown as string,
6161
},
6262
};
6363

@@ -69,4 +69,4 @@ describe("configUtils", () => {
6969
});
7070
});
7171
});
72-
});
72+
});

client/src/utils/configUtils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,16 @@ export const getMCPServerRequestMaxTotalTimeout = (
2828
return config.MCP_REQUEST_MAX_TOTAL_TIMEOUT.value as number;
2929
};
3030

31-
export const getMCPProxyAuthToken = (config: InspectorConfig): string => {
32-
return config.MCP_PROXY_AUTH_TOKEN.value as string;
31+
export const getMCPProxyAuthToken = (
32+
config: InspectorConfig,
33+
): {
34+
token: string;
35+
header: string;
36+
} => {
37+
return {
38+
token: config.MCP_PROXY_AUTH_TOKEN.value as string,
39+
header: "X-MCP-Proxy-Auth",
40+
};
3341
};
3442

3543
const getSearchParam = (key: string): string | null => {

0 commit comments

Comments
 (0)