11import { spawn , type ChildProcessWithoutNullStreams } from 'node:child_process' ;
22import { join , dirname } from 'node:path' ;
33import { fileURLToPath } from 'node:url' ;
4- import { it , expect } from 'vitest' ;
4+ import { it , expect , afterEach } from 'vitest' ;
55
66const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
77const packageDir = join ( __dirname , '..' ) ;
@@ -64,8 +64,11 @@ const stopServer = async (testProcess: ChildProcessWithoutNullStreams): Promise<
6464 } ) ;
6565} ;
6666
67+ let runningProcess : ChildProcessWithoutNullStreams | null = null ;
68+
6769it ( 'should execute as a standalone file and start the server on custom port' , async ( ) => {
6870 const { output, process : testProcess , started } = await startServer ( 9999 ) ;
71+ runningProcess = testProcess ;
6972
7073 expect ( started ) . toBe ( true ) ;
7174 expect ( output ) . toContain ( 'Starting Theme Wizard server...' ) ;
@@ -76,10 +79,17 @@ it('should execute as a standalone file and start the server on custom port', as
7679
7780it ( 'should execute with default port 8080 when PORT env is not set' , async ( ) => {
7881 const { output, process : testProcess , started } = await startServer ( ) ;
82+ runningProcess = testProcess ;
7983
8084 expect ( started ) . toBe ( true ) ;
8185 expect ( output ) . toContain ( 'Starting Theme Wizard server...' ) ;
8286 expect ( output ) . toContain ( 'http://[::]:8080/' ) ;
8387
8488 await stopServer ( testProcess ) ;
8589} ) ;
90+
91+ afterEach ( ( ) => {
92+ if ( runningProcess ) {
93+ stopServer ( runningProcess ) ;
94+ }
95+ } ) ;
0 commit comments