@@ -58,7 +58,6 @@ if (existsSync(configPath)) {
5858let browserInstance = null ;
5959let screenshotServer = null ;
6060let isShuttingDown = false ;
61- let cleanupReason = 'unknown' ;
6261
6362/**
6463 * Clean up resources and exit
@@ -68,7 +67,6 @@ let cleanupReason = 'unknown';
6867async function cleanup ( reason = 'unknown' , exitCode = 0 ) {
6968 if ( isShuttingDown ) return ;
7069 isShuttingDown = true ;
71- cleanupReason = reason ;
7270
7371 if ( process . env . VIZZLY_LOG_LEVEL === 'debug' ) {
7472 console . error ( `[vizzly-testem-launcher] Cleanup triggered: ${ reason } ` ) ;
@@ -120,22 +118,23 @@ async function main() {
120118 playwrightOptions,
121119 onPageCreated : page => {
122120 setPage ( page ) ;
123- page . on ( 'close' , ( ) => cleanup ( 'page-close' ) ) ;
121+ page . on ( 'close' , async ( ) => await cleanup ( 'page-close' ) ) ;
124122 } ,
125- onBrowserDisconnected : ( ) => cleanup ( 'browser-disconnected' ) ,
123+ onBrowserDisconnected : async ( ) => await cleanup ( 'browser-disconnected' ) ,
126124 } ) ;
127125
128126 // 4. Listen for browser crashes
129127 let { page } = browserInstance ;
130- page . on ( 'crash' , ( ) => {
128+ page . on ( 'crash' , async ( ) => {
131129 console . error ( '[vizzly-testem-launcher] Page crashed!' ) ;
132- cleanup ( 'page-crash' , 1 ) ;
130+ await cleanup ( 'page-crash' , 1 ) ;
133131 } ) ;
134132
135133 // 5. Keep process alive until cleanup is called
136134 await new Promise ( ( ) => { } ) ;
137135 } catch ( error ) {
138136 console . error ( '[vizzly-testem-launcher] Failed to start:' , error . message ) ;
137+ console . error ( error . stack ) ;
139138
140139 if ( screenshotServer ) {
141140 await stopScreenshotServer ( screenshotServer ) . catch ( ( ) => { } ) ;
@@ -146,24 +145,24 @@ async function main() {
146145}
147146
148147// Handle graceful shutdown signals from Testem
149- process . on ( 'SIGTERM' , ( ) => cleanup ( 'SIGTERM' ) ) ;
150- process . on ( 'SIGINT' , ( ) => cleanup ( 'SIGINT' ) ) ;
151- process . on ( 'SIGHUP' , ( ) => cleanup ( 'SIGHUP' ) ) ;
148+ process . on ( 'SIGTERM' , async ( ) => await cleanup ( 'SIGTERM' ) ) ;
149+ process . on ( 'SIGINT' , async ( ) => await cleanup ( 'SIGINT' ) ) ;
150+ process . on ( 'SIGHUP' , async ( ) => await cleanup ( 'SIGHUP' ) ) ;
152151
153152// Handle unexpected errors
154- process . on ( 'uncaughtException' , error => {
153+ process . on ( 'uncaughtException' , async error => {
155154 console . error ( '[vizzly-testem-launcher] Uncaught exception:' , error . message ) ;
156155 console . error ( error . stack ) ;
157- cleanup ( 'uncaughtException' , 1 ) ;
156+ await cleanup ( 'uncaughtException' , 1 ) ;
158157} ) ;
159158
160- process . on ( 'unhandledRejection' , ( reason , promise ) => {
159+ process . on ( 'unhandledRejection' , async ( reason , promise ) => {
161160 console . error ( '[vizzly-testem-launcher] Unhandled rejection at:' , promise ) ;
162161 console . error ( '[vizzly-testem-launcher] Reason:' , reason ) ;
163162 if ( reason instanceof Error ) {
164163 console . error ( reason . stack ) ;
165164 }
166- cleanup ( 'unhandledRejection' , 1 ) ;
165+ await cleanup ( 'unhandledRejection' , 1 ) ;
167166} ) ;
168167
169168main ( ) ;
0 commit comments