We occasionally get reports of Karma tests disconnecting, particularly when testing with Safari (or mobile Safari). Local output will look something like:
20 05 2016 09:37:32.994:INFO [Mobile Safari 9.0.0 (iOS 9.2.0)]: Connected on socket /#beysgLN0Ydo-kpT6AAAX with id 11041574
................................................................................
....................20 05 2016 09:37:45.912:WARN [Mobile Safari 9.0.0 (iOS 9.2.0)]: Disconnected (1 times), because no message in 10000 ms.
20 05 2016 09:37:45.965:ERROR [reporter.sauce]: ✖ Test Disconnected
Mobile Safari 9.0.0 (iOS 9.2.0): Executed 100 of 233 DISCONNECTED (10.276 secs / 0.116 secs)
This is generally related to timeouts in Karma. This issue does seem to be prevalent when running Karma tests using any cloud-based selenium grid such as Sauce Labs. When running such tests, we first fire up a VM, then fire up a simulator running Android, and finally run the javascript tests. This of course takes time – and a lot of the time a lot more time than the default settings of Karma permit. Recent versions of Karma have gained a few new options and the following options in your karma.config.js will help alleviate these issues:
// to avoid DISCONNECTED messages browserDisconnectTimeout : 10000, // default 2000 browserDisconnectTolerance : 1, // default 0 browserNoActivityTimeout : 4*60*1000 //default 10000 captureTimeout : 4*60*1000 //default 60000
Even after removing the test specific timeouts, some tests might still time out after mocha's default setting of two seconds. When running mocha on the command line, one can override the default timeout setting, and it turns out we can do it in the configuration as well. Simply add the following to your config to increase the default timeout.
client: { mocha: { timeout : 20000 // 20 seconds }