Skip to content

Commit dd909f1

Browse files
committed
fix: Prevent process from hanging after tests complete
- Add force-exit timeout (100ms) in run command to ensure process exits - Respects --no-exit flag if explicitly set - Increase browser stop timeout from 5s to 10s for browser restart strategy This fixes an issue where tests would complete successfully but the Node.js process would hang indefinitely, waiting for the event loop to clear. The issue was caused by Mocha 11.x waiting for all handles to close, but some browser-related handles may remain open even after proper cleanup. The force-exit gives cleanup operations time to complete (100ms) then explicitly calls process.exit() to terminate the process cleanly.
1 parent 282e58a commit dd909f1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/command/run.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,14 @@ export default async function (test, options) {
4242
process.exitCode = 1
4343
} finally {
4444
await codecept.teardown()
45+
46+
// Force exit if event loop doesn't clear naturally
47+
// This is needed because some helpers (like Playwright) may leave handles open
48+
// even after proper cleanup, preventing natural process termination
49+
if (!options.noExit) {
50+
setTimeout(() => {
51+
process.exit(process.exitCode || 0)
52+
}, 100)
53+
}
4554
}
4655
}

lib/helper/Playwright.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,10 @@ class Playwright extends Helper {
718718
const pages = await this.browserContext.pages()
719719
await Promise.allSettled(pages.map(p => p.close().catch(() => {})))
720720
}
721-
// Use timeout to prevent hanging
721+
// Use timeout to prevent hanging (10s should be enough for browser cleanup)
722722
await Promise.race([
723723
this._stopBrowser(),
724-
new Promise((_, reject) => setTimeout(() => reject(new Error('Browser stop timeout')), 5000)),
724+
new Promise((_, reject) => setTimeout(() => reject(new Error('Browser stop timeout')), 10000)),
725725
])
726726
} catch (e) {
727727
console.warn('Warning during browser restart in _after:', e.message)

0 commit comments

Comments
 (0)