@@ -13,11 +13,11 @@ function getMCPServers() {
13
13
try {
14
14
const stateData = readFileSync ( testStateFile , 'utf-8' )
15
15
const state = JSON . parse ( stateData )
16
-
16
+
17
17
if ( ! state . honoPort ) {
18
18
throw new Error ( 'hono-mcp port not found in test state' )
19
19
}
20
-
20
+
21
21
return [
22
22
{
23
23
name : 'hono-mcp' ,
@@ -40,48 +40,48 @@ async function connectToMCPServer(page: Page, serverUrl: string): Promise<{ succ
40
40
// Navigate to the inspector
41
41
const stateData = readFileSync ( testStateFile , 'utf-8' )
42
42
const state = JSON . parse ( stateData )
43
-
43
+
44
44
if ( ! state . staticPort ) {
45
45
throw new Error ( 'Static server port not available - state: ' + JSON . stringify ( state ) )
46
46
}
47
47
const staticPort = state . staticPort
48
-
48
+
49
49
await page . goto ( `http://localhost:${ staticPort } ` )
50
-
50
+
51
51
// Wait for the page to load
52
52
await page . waitForSelector ( 'input[placeholder="Enter MCP server URL"]' , { timeout : 10000 } )
53
-
53
+
54
54
// Enter the server URL
55
55
const urlInput = page . locator ( 'input[placeholder="Enter MCP server URL"]' )
56
56
await urlInput . fill ( serverUrl )
57
-
57
+
58
58
// Click connect button
59
59
const connectButton = page . locator ( 'button:has-text("Connect")' )
60
60
await connectButton . click ( )
61
-
61
+
62
62
// Wait for connection attempt to complete (max 10 seconds)
63
63
await page . waitForTimeout ( 1000 ) // Initial wait
64
-
64
+
65
65
// Check for connection status
66
66
let attempts = 0
67
67
const maxAttempts = 20 // 10 seconds total (500ms * 20)
68
68
let isConnected = false
69
-
69
+
70
70
while ( attempts < maxAttempts && ! isConnected ) {
71
71
try {
72
72
// Check if status badge shows "Connected"
73
73
const statusBadge = page . locator ( '.px-2.py-1.rounded-full' )
74
- if ( await statusBadge . count ( ) > 0 ) {
74
+ if ( ( await statusBadge . count ( ) ) > 0 ) {
75
75
const statusText = await statusBadge . textContent ( { timeout : 500 } )
76
76
if ( statusText ?. toLowerCase ( ) . includes ( 'connected' ) ) {
77
77
isConnected = true
78
78
break
79
79
}
80
80
}
81
-
81
+
82
82
// Also check if tools count is > 0
83
83
const toolsHeader = page . locator ( 'h3:has-text("Available Tools")' )
84
- if ( await toolsHeader . count ( ) > 0 ) {
84
+ if ( ( await toolsHeader . count ( ) ) > 0 ) {
85
85
const toolsText = await toolsHeader . textContent ( )
86
86
if ( toolsText && / \d + / . test ( toolsText ) ) {
87
87
const toolsCount = parseInt ( toolsText . match ( / \d + / ) ?. [ 0 ] || '0' )
@@ -94,18 +94,18 @@ async function connectToMCPServer(page: Page, serverUrl: string): Promise<{ succ
94
94
} catch ( e ) {
95
95
// Continue waiting
96
96
}
97
-
97
+
98
98
await page . waitForTimeout ( 500 )
99
99
attempts ++
100
100
}
101
-
101
+
102
102
// Extract available tools
103
103
const tools : string [ ] = [ ]
104
104
try {
105
105
// Look for tool cards in the tools container
106
106
const toolCards = page . locator ( '.bg-white.rounded.border' )
107
107
const toolCount = await toolCards . count ( )
108
-
108
+
109
109
for ( let i = 0 ; i < toolCount ; i ++ ) {
110
110
const toolNameElement = toolCards . nth ( i ) . locator ( 'h4.font-bold.text-base.text-black' )
111
111
const toolName = await toolNameElement . textContent ( )
@@ -116,18 +116,18 @@ async function connectToMCPServer(page: Page, serverUrl: string): Promise<{ succ
116
116
} catch ( e ) {
117
117
console . warn ( 'Could not extract tools list:' , e )
118
118
}
119
-
119
+
120
120
// Extract debug log
121
121
let debugLog = ''
122
122
try {
123
123
const debugContainer = page . locator ( '.h-32.overflow-y-auto.font-mono.text-xs' )
124
- if ( await debugContainer . count ( ) > 0 ) {
125
- debugLog = await debugContainer . first ( ) . textContent ( ) || ''
124
+ if ( ( await debugContainer . count ( ) ) > 0 ) {
125
+ debugLog = ( await debugContainer . first ( ) . textContent ( ) ) || ''
126
126
}
127
127
} catch ( e ) {
128
128
console . warn ( 'Could not extract debug log:' , e )
129
129
}
130
-
130
+
131
131
return {
132
132
success : isConnected ,
133
133
tools,
@@ -149,7 +149,7 @@ describe('MCP Connection Integration Tests', () => {
149
149
if ( browser ) {
150
150
await browser . close ( )
151
151
}
152
-
152
+
153
153
// Force cleanup before Vitest exits - don't throw errors
154
154
const state = globalThis . __INTEGRATION_TEST_STATE__
155
155
try {
@@ -160,7 +160,7 @@ describe('MCP Connection Integration Tests', () => {
160
160
} catch ( e ) {
161
161
// Ignore errors - process might already be dead
162
162
}
163
-
163
+
164
164
try {
165
165
if ( state ?. staticServer ) {
166
166
state . staticServer . close ( )
@@ -174,7 +174,7 @@ describe('MCP Connection Integration Tests', () => {
174
174
beforeEach ( async ( ) => {
175
175
const context = await browser . newContext ( )
176
176
page = await context . newPage ( )
177
-
177
+
178
178
// Enable console logging for debugging
179
179
page . on ( 'console' , ( msg ) => {
180
180
if ( msg . type ( ) === 'error' ) {
@@ -192,19 +192,19 @@ describe('MCP Connection Integration Tests', () => {
192
192
193
193
test ( 'should connect to all MCP servers and retrieve tools' , async ( ) => {
194
194
const servers = getMCPServers ( )
195
-
195
+
196
196
for ( const server of servers ) {
197
197
console . log ( `\n🔗 Testing connection to ${ server . name } at ${ server . url } ` )
198
-
198
+
199
199
const result = await connectToMCPServer ( page , server . url )
200
-
200
+
201
201
if ( result . success ) {
202
202
console . log ( `✅ Successfully connected to ${ server . name } ` )
203
203
console . log ( `📋 Available tools (${ result . tools . length } ):` )
204
204
result . tools . forEach ( ( tool , index ) => {
205
205
console . log ( ` ${ index + 1 } . ${ tool } ` )
206
206
} )
207
-
207
+
208
208
// Verify connection success
209
209
expect ( result . success ) . toBe ( true )
210
210
expect ( result . tools . length ) . toBeGreaterThanOrEqual ( server . expectedTools )
@@ -214,7 +214,7 @@ describe('MCP Connection Integration Tests', () => {
214
214
console . log ( `🐛 Debug log:` )
215
215
console . log ( result . debugLog )
216
216
}
217
-
217
+
218
218
// Fail the test with detailed information
219
219
throw new Error ( `Failed to connect to ${ server . name } . Debug log: ${ result . debugLog } ` )
220
220
}
0 commit comments