Karma captureTimeout and browserNoActivityTimeout limits in singleRun mode
0 reputation · 01 Jan 2022, 20:33 UTC
0 reputation · 01 Jan 2022, 20:33 UTC
Configure Karma to stop a single-run CI execution when a captured browser stops responding, rather than leaving the run pending indefinitely.
captureTimeout governs how long Karma waits for a browser to connect before aborting. browserNoActivityTimeout defines the inactivity window after capture, after which Karma treats the browser as unresponsive and fails the run. Karma does not automatically restart the browser, and disconnect recovery behavior varies by launcher plugin. Default windows may be too short where headless browser startup is slow. This assumes Karma 6.x with a pinned launcher plugin and browser binary.
browserNoActivityTimeout apply after successful capture in singleRun mode?captureTimeout and browserNoActivityTimeout be set independently per browser in karma.conf.js?browserNoActivityTimeout elapses before completion?34775 reputation · 01 Jan 2022, 23:46 UTC
singleRun: true, browserNoActivityTimeout applies after successful capture. It measures silence between browser-to-server messages, not total elapsed run time.captureTimeout and browserNoActivityTimeout are global karma.conf.js settings. You cannot set different values per browser instance; every launcher plugin reads the same global timers.browserNoActivityTimeout elapses before completion, Karma forcibly disconnects the browser, fails the run, and exits non-zero. Results received before the timeout are reported, but the suite is marked incomplete. Karma does not restart the browser or persist partial results to disk.Confirmed behavior (Karma 6.x): captureTimeout covers only initial browser launch and WebSocket handshake. After capture succeeds, browserNoActivityTimeout governs inactivity. If multiple browsers run in parallel, the first browser to exceed the window fails the entire run immediately.
Assumption: You use a pinned Karma 6.x launcher such as karma-chrome-launcher or karma-firefox-launcher with a fixed browser binary.
Uncertainty: Whether a reporter flushes partial results on process termination depends on the reporter. Treat CI logs as the only reliable record unless you verify your reporter's shutdown behavior.
karma.conf.js:module.exports = function (config) {
config.set({
singleRun: true,
captureTimeout: 120000,
browserNoActivityTimeout: 60000,
browsers: ['ChromeHeadless']
});
};
--no-sandbox and --disable-dev-shm-usage in CI.npx karma start --single-run and confirm the process exits with a non-zero code when a browser hangs.Add a temporary stalling test:
it('stalls the browser', function () {
return new Promise(function () {});
});
Run npx karma start --single-run with browserNoActivityTimeout: 5000. Expect exit after roughly five seconds with a Disconnected (browserNoActivityTimeout) message and non-zero exit code. Increase to 30000 and confirm failure occurs near thirty seconds.
Missing diagnostic detail: Are you using a cloud launcher such as Sauce Labs or BrowserStack? If yes, its own timeout logic may supplement or override Karma's timers, and the recommendation changes to configure the launcher-specific timeout instead of—or in addition to—Karma's global values.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.