@@ -299,8 +299,111 @@ async function runErrorTest(testName, ...args) {
299299 }
300300}
301301
302+ // Function to run a web client startup test
303+ async function runWebClientTest ( testName , ...args ) {
304+ const outputFile = path . join (
305+ OUTPUT_DIR ,
306+ `${ testName . replace ( / \/ / g, "_" ) } .log` ,
307+ ) ;
308+
309+ console . log ( `\n${ colors . YELLOW } Testing: ${ testName } ${ colors . NC } ` ) ;
310+ TOTAL_TESTS ++ ;
311+
312+ // Run the command and capture output
313+ console . log (
314+ `${ colors . BLUE } Command: node ${ BUILD_DIR } /cli.js ${ args . join ( " " ) } ${ colors . NC } ` ,
315+ ) ;
316+
317+ try {
318+ // Create a write stream for the output file
319+ const outputStream = fs . createWriteStream ( outputFile ) ;
320+
321+ // Spawn the process
322+ return new Promise ( ( resolve ) => {
323+ const child = spawn ( "node" , [ path . join ( BUILD_DIR , "cli.js" ) , ...args ] , {
324+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
325+ env : {
326+ ...process . env ,
327+ MCP_AUTO_OPEN_ENABLED : "false" , // Prevent browser from opening
328+ SERVER_PORT : "9999" , // Use a different port for testing
329+ CLIENT_PORT : "9998" , // Use a different port for testing
330+ } ,
331+ } ) ;
332+
333+ let output = "" ;
334+ let serverStarted = false ;
335+
336+ child . stdout . on ( "data" , ( data ) => {
337+ output += data . toString ( ) ;
338+ outputStream . write ( data ) ;
339+
340+ // Check if server started successfully
341+ if ( output . includes ( "MCP Inspector is up and running" ) ) {
342+ serverStarted = true ;
343+ // Kill the process after successful startup
344+ child . kill ( ) ;
345+ }
346+ } ) ;
347+
348+ child . stderr . on ( "data" , ( data ) => {
349+ output += data . toString ( ) ;
350+ outputStream . write ( data ) ;
351+ } ) ;
352+
353+ const timeout = setTimeout ( ( ) => {
354+ console . log ( `${ colors . YELLOW } Test timed out: ${ testName } ${ colors . NC } ` ) ;
355+ child . kill ( ) ;
356+ } , 5000 ) ; // 5 second timeout for web client startup
357+
358+ child . on ( "close" , ( code ) => {
359+ clearTimeout ( timeout ) ;
360+ outputStream . end ( ) ;
361+
362+ if ( serverStarted ) {
363+ console . log ( `${ colors . GREEN } ✓ Test passed: ${ testName } ${ colors . NC } ` ) ;
364+ console . log ( `${ colors . BLUE } Server started successfully${ colors . NC } ` ) ;
365+ PASSED_TESTS ++ ;
366+ resolve ( true ) ;
367+ } else {
368+ console . log ( `${ colors . RED } ✗ Test failed: ${ testName } ${ colors . NC } ` ) ;
369+ console . log ( `${ colors . RED } Error output:${ colors . NC } ` ) ;
370+ console . log (
371+ output
372+ . split ( "\n" )
373+ . map ( ( line ) => ` ${ line } ` )
374+ . join ( "\n" ) ,
375+ ) ;
376+ FAILED_TESTS ++ ;
377+
378+ // Stop after any error is encountered
379+ console . log (
380+ `${ colors . YELLOW } Stopping tests due to error. Please validate and fix before continuing.${ colors . NC } ` ,
381+ ) ;
382+ process . exit ( 1 ) ;
383+ }
384+ } ) ;
385+ } ) ;
386+ } catch ( error ) {
387+ console . error (
388+ `${ colors . RED } Error running test: ${ error . message } ${ colors . NC } ` ,
389+ ) ;
390+ FAILED_TESTS ++ ;
391+ process . exit ( 1 ) ;
392+ }
393+ }
394+
302395// Run all tests
303396async function runTests ( ) {
397+ console . log (
398+ `\n${ colors . YELLOW } === Running Basic Tests ===${ colors . NC } ` ,
399+ ) ;
400+
401+ // Test 0: Basic web client mode without any arguments (regression test for npx .)
402+ await runWebClientTest (
403+ "web_client_no_args"
404+ // No arguments - should start web client without error
405+ ) ;
406+
304407 console . log (
305408 `\n${ colors . YELLOW } === Running Basic CLI Mode Tests ===${ colors . NC } ` ,
306409 ) ;
0 commit comments