@@ -43,13 +43,32 @@ function spawnLogged(cmd: string, args: string[],
4343 return child ;
4444}
4545
46- async function waitFor ( url : string , label : string , timeoutMs : number ) {
46+ function assertRunning ( child : ChildProcess , label : string ) : void {
47+ if ( child . exitCode !== null || child . signalCode !== null || child . pid == null ) {
48+ throw new Error (
49+ `${ label } exited before readiness ` +
50+ `(code=${ child . exitCode } , signal=${ child . signalCode } )` ,
51+ ) ;
52+ }
53+ try {
54+ process . kill ( child . pid , 0 ) ;
55+ } catch {
56+ throw new Error ( `${ label } process ${ child . pid } is not running` ) ;
57+ }
58+ }
59+
60+ async function waitFor ( url : string , label : string , timeoutMs : number ,
61+ child : ChildProcess ) {
4762 const deadline = Date . now ( ) + timeoutMs ;
4863 let lastErr : string = "no attempts" ;
4964 while ( Date . now ( ) < deadline ) {
65+ assertRunning ( child , label ) ;
5066 try {
5167 const res = await fetch ( url ) ;
52- if ( res . ok ) return ;
68+ if ( res . ok ) {
69+ assertRunning ( child , label ) ;
70+ return ;
71+ }
5372 lastErr = `HTTP ${ res . status } ` ;
5473 } catch ( e ) {
5574 lastErr = String ( e ) ;
@@ -99,7 +118,7 @@ export default async function globalSetup(): Promise<void> {
99118 } , null , 2 ) ) ;
100119
101120 await Promise . all ( [
102- waitFor ( `${ BACKEND_URL } /health` , "backend" , 30_000 ) ,
103- waitFor ( FRONTEND_URL , "frontend" , 30_000 ) ,
121+ waitFor ( `${ BACKEND_URL } /health` , "backend" , 30_000 , handles . backend ) ,
122+ waitFor ( FRONTEND_URL , "frontend" , 30_000 , handles . frontend ) ,
104123 ] ) ;
105124}
0 commit comments