@@ -23,27 +23,6 @@ function isPortInUse(port: number): boolean {
2323 }
2424}
2525
26- // Helper function to wait for server to be ready with retry mechanism
27- async function waitForServerReady ( options : {
28- port : number ;
29- timeoutMs ?: number ;
30- retryIntervalMs ?: number ;
31- } ) : Promise < boolean > {
32- const { port, timeoutMs = 30000 , retryIntervalMs = 1000 } = options ;
33- const startTime = Date . now ( ) ;
34-
35- while ( Date . now ( ) - startTime < timeoutMs ) {
36- if ( isPortInUse ( port ) ) {
37- return true ; // Server is ready
38- }
39-
40- // Wait before next retry
41- await new Promise ( ( resolve ) => setTimeout ( resolve , retryIntervalMs ) ) ;
42- }
43-
44- return false ; // Timeout reached, server not ready
45- }
46-
4726describe ( "create-handbook CLI" , ( ) => {
4827 it ( "creates a new site with valid name" , async ( ) => {
4928 const siteName = "test-handbook" ;
@@ -115,7 +94,16 @@ describe("create-handbook CLI", () => {
11594 } ) ;
11695
11796 // Wait for server to be ready with retry mechanism
118- const serverReady = await waitForServerReady ( { port : 3000 } ) ;
97+ let serverReady = false ;
98+ let attempts = 0 ;
99+ const maxAttempts = 30 ; // 30 seconds total
100+
101+ while ( ! serverReady && attempts < maxAttempts ) {
102+ await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) ) ;
103+ serverReady = isPortInUse ( 3000 ) ;
104+ attempts ++ ;
105+ }
106+
119107 expect ( serverReady ) . toBe ( true ) ;
120108
121109 // Send Ctrl+C (SIGINT) to the process and wait for it to exit
0 commit comments