From 9c3e642e406802d624af1880634b863cda9e7c08 Mon Sep 17 00:00:00 2001 From: Bernd Konnerth Date: Mon, 26 Jun 2023 11:30:43 +0200 Subject: [PATCH] fix: karma hangs after finishing tests successfully After successfully finishing all tests, karma hangs for 30 sec with this message: Chrome Headless 114.0.5735.35 (Windows 10) ERROR Disconnected , because no message in 30000 ms. Chrome Headless 114.0.5735.35 (Windows 10): Executed 634 of 634 DISCONNECTED (34.58 secs / 3.303 secs) Chrome Headless 114.0.5735.35 (Windows 10) ERROR Chrome Headless 114.0.5735.35 (Windows 10): Executed 634 of 634 DISCONNECTED (34.58 secs / 3.303 secs) This only happens when executing more than approx 620 tests. See more details here: https://stackoverflow.com/questions/76457941/karma-hangs-for-30-seconds-after-successfully-executing-unit-tests --- lib/browser.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/browser.js b/lib/browser.js index aa8795792..0cdb0757d 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -192,12 +192,14 @@ class Browser { if (this.noActivityTimeout) { this.clearNoActivityTimeout() - this.noActivityTimeoutId = this.timer.setTimeout(() => { - this.lastResult.totalTimeEnd() - this.lastResult.disconnected = true - this.disconnect(`, because no message in ${this.noActivityTimeout} ms.`) - this.emitter.emit('browser_complete', this) - }, this.noActivityTimeout) + if (this.state !== 'DISCONNECTED') { + this.noActivityTimeoutId = this.timer.setTimeout(() => { + this.lastResult.totalTimeEnd() + this.lastResult.disconnected = true + this.disconnect(`, because no message in ${this.noActivityTimeout} ms.`) + this.emitter.emit('browser_complete', this) + }, this.noActivityTimeout) + } } }