@@ -97,29 +97,6 @@ describe( 'WordPress Server Manager', () => {
9797 } ) ;
9898 }
9999
100- function mockStartProcessExit ( {
101- beforeExit,
102- stderrTail,
103- } : {
104- beforeExit ?: ( ) => void ;
105- stderrTail ?: string ;
106- } = { } ) : void {
107- vi . mocked ( daemonClient . startProcess ) . mockImplementation ( async ( ) => {
108- setImmediate ( ( ) => {
109- beforeExit ?.( ) ;
110- mockBus . emit ( 'process-event' , {
111- process : {
112- name : mockProcessDescription . name ,
113- pm_id : mockProcessDescription . pmId ,
114- } ,
115- event : 'exit' ,
116- ...( stderrTail ? { stderrTail } : { } ) ,
117- } ) ;
118- } ) ;
119- return mockProcessDescription ;
120- } ) ;
121- }
122-
123100 describe ( 'isServerRunning' , ( ) => {
124101 it ( 'should check if process is running with correct process name' , async ( ) => {
125102 const mockProcess = {
@@ -287,7 +264,15 @@ describe( 'WordPress Server Manager', () => {
287264
288265 it ( 'should surface an error when the child process exits before becoming ready' , async ( ) => {
289266 // Do not emit `ready`; instead emit an `exit` event to simulate a crash during startup.
290- mockStartProcessExit ( ) ;
267+ setTimeout ( ( ) => {
268+ mockBus . emit ( 'process-event' , {
269+ process : {
270+ name : mockProcessDescription . name ,
271+ pm_id : mockProcessDescription . pmId ,
272+ } ,
273+ event : 'exit' ,
274+ } ) ;
275+ } , 10 ) ;
291276
292277 await expect ( startWordPressServer ( mockSiteData , mockLogger ) ) . rejects . toThrow (
293278 / e x i t e d b e f o r e b e c o m i n g r e a d y /
@@ -296,7 +281,17 @@ describe( 'WordPress Server Manager', () => {
296281
297282 it ( 'should include the child stderr tail in the error when the daemon provides it' , async ( ) => {
298283 const stderrTail = 'SyntaxError: The requested module did not provide an export named X' ;
299- mockStartProcessExit ( { stderrTail } ) ;
284+
285+ setTimeout ( ( ) => {
286+ mockBus . emit ( 'process-event' , {
287+ process : {
288+ name : mockProcessDescription . name ,
289+ pm_id : mockProcessDescription . pmId ,
290+ } ,
291+ event : 'exit' ,
292+ stderrTail,
293+ } ) ;
294+ } , 10 ) ;
300295
301296 await expect ( startWordPressServer ( mockSiteData , mockLogger ) ) . rejects . toThrow (
302297 new RegExp ( stderrTail . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) )
@@ -332,11 +327,16 @@ describe( 'WordPress Server Manager', () => {
332327 await fs . promises . mkdir ( path . join ( sitePath , 'wp-content' ) , { recursive : true } ) ;
333328 const logPath = path . join ( sitePath , 'wp-content' , STUDIO_ERROR_LOG_FILENAME ) ;
334329
335- mockStartProcessExit ( {
336- beforeExit : ( ) => {
337- fs . writeFileSync ( logPath , 'PHP Fatal error: Uncaught Error: Failed opening required' ) ;
338- } ,
339- } ) ;
330+ setTimeout ( ( ) => {
331+ fs . writeFileSync ( logPath , 'PHP Fatal error: Uncaught Error: Failed opening required' ) ;
332+ mockBus . emit ( 'process-event' , {
333+ process : {
334+ name : mockProcessDescription . name ,
335+ pm_id : mockProcessDescription . pmId ,
336+ } ,
337+ event : 'exit' ,
338+ } ) ;
339+ } , 10 ) ;
340340
341341 await expect (
342342 startWordPressServer ( { ...mockSiteData , path : sitePath } , mockLogger )
@@ -350,7 +350,15 @@ describe( 'WordPress Server Manager', () => {
350350 const logPath = path . join ( sitePath , 'wp-content' , 'debug.log' ) ;
351351 fs . writeFileSync ( logPath , 'PHP Fatal error: from a previous run' ) ;
352352
353- mockStartProcessExit ( ) ;
353+ setTimeout ( ( ) => {
354+ mockBus . emit ( 'process-event' , {
355+ process : {
356+ name : mockProcessDescription . name ,
357+ pm_id : mockProcessDescription . pmId ,
358+ } ,
359+ event : 'exit' ,
360+ } ) ;
361+ } , 10 ) ;
354362
355363 const error : Error = await startWordPressServer (
356364 { ...mockSiteData , path : sitePath , enableDebugLog : true } ,
@@ -370,11 +378,16 @@ describe( 'WordPress Server Manager', () => {
370378 await fs . promises . mkdir ( path . join ( sitePath , 'wp-content' ) , { recursive : true } ) ;
371379 const logPath = path . join ( sitePath , 'wp-content' , 'debug.log' ) ;
372380
373- mockStartProcessExit ( {
374- beforeExit : ( ) => {
375- fs . writeFileSync ( logPath , 'PHP Fatal error: Uncaught Error: Failed opening required' ) ;
376- } ,
377- } ) ;
381+ setTimeout ( ( ) => {
382+ fs . writeFileSync ( logPath , 'PHP Fatal error: Uncaught Error: Failed opening required' ) ;
383+ mockBus . emit ( 'process-event' , {
384+ process : {
385+ name : mockProcessDescription . name ,
386+ pm_id : mockProcessDescription . pmId ,
387+ } ,
388+ event : 'exit' ,
389+ } ) ;
390+ } , 10 ) ;
378391
379392 await expect (
380393 startWordPressServer (
0 commit comments