Skip to content

Commit c212a18

Browse files
committed
Add auto-exit to _afterSuite for BROWSER_RESTART=browser mode
- Process now exits cleanly after suite completes - Critical for browser restart mode where afterSuite is final cleanup - Prevents hanging when all tests in suite are complete - Uses same 2-second delayed exit as _cleanup()
1 parent bbbe770 commit c212a18

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/helper/Playwright.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,18 @@ class Playwright extends Helper {
869869
this.testFailures.push(`Final cleanup failed: ${e.message}`)
870870
}
871871

872+
// Schedule a delayed exit to prevent process hanging due to Playwright event loops
873+
// This is especially important for BROWSER_RESTART=browser mode where afterSuite is the final cleanup
874+
// Give it 2 seconds for any pending operations to complete
875+
if (!process.env.CODECEPT_DISABLE_AUTO_EXIT) {
876+
setTimeout(() => {
877+
if (process.listenerCount('exit') === 0) {
878+
// No other exit handlers, safe to exit
879+
process.exit(process.exitCode || 0)
880+
}
881+
}, 2000).unref()
882+
}
883+
872884
// Clean up session pages explicitly to prevent hanging references
873885
try {
874886
if (this.sessionPages && Object.keys(this.sessionPages).length > 0) {

0 commit comments

Comments
 (0)