diff --git a/docs/config/01-configuration-file.md b/docs/config/01-configuration-file.md index 542b55a25..4f064ea0f 100644 --- a/docs/config/01-configuration-file.md +++ b/docs/config/01-configuration-file.md @@ -59,10 +59,10 @@ Under the hood Karma uses ts-node to transpile TypeScript to JavaScript. If the Create a JavaScript configuration file that overrides the module format. ```javascript // karma.conf.js -require('ts-node').register({ - compilerOptions: { - module: 'commonjs' - } +require('ts-node').register({ + compilerOptions: { + module: 'commonjs' + } }); require('./karma.conf.ts'); ``` @@ -678,6 +678,14 @@ Note: Just about all additional reporters in Karma (other than progress) require The CLI option should be a path to a file that exports the format function. This can be a function exported at the root of the module or an export named `formatError`. +## pingTimeout +**Type** Number + +**Default** 5000 + +**Description** Socket.io pingTimeout in ms, https://socket.io/docs/server-api/#new-Server-httpServer-options. +Very slow networks may need values up to 60000. Larger values delay discovery of deadlock in tests or browser crashes. + ## restartOnFileChange **Type:** Boolean diff --git a/lib/config.js b/lib/config.js index adf9840e2..eec445dc5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -204,6 +204,10 @@ function normalizeConfig (config, configFilePath) { assert(helper.isNumber(config.browserSocketTimeout), 'Invalid configuration: browserSocketTimeout option must be a number.') } + if (config.pingTimeout) { + assert(helper.isNumber(config.pingTimeout), 'Invalid configuration: pingTimeout option must be a number.') + } + const defaultClient = config.defaultClient || {} Object.keys(defaultClient).forEach(function (key) { const option = config.client[key] @@ -299,6 +303,7 @@ class Config { this.singleRun = false this.browsers = [] this.captureTimeout = 60000 + this.pingTimeout = 5000 this.proxies = {} this.proxyValidateSSL = true this.preprocessors = {} diff --git a/lib/server.js b/lib/server.js index fdbb6c19e..c1acb241c 100644 --- a/lib/server.js +++ b/lib/server.js @@ -44,7 +44,9 @@ function createSocketIoServer (webServer, executor, config) { destroyUpgrade: false, path: config.urlRoot + 'socket.io/', transports: config.transports, - forceJSONP: config.forceJSONP + forceJSONP: config.forceJSONP, + // Default is 5000 in socket.io v2.x. + pingTimeout: config.pingTimeout || 5000 }) // hack to overcome circular dependency diff --git a/test/unit/config.spec.js b/test/unit/config.spec.js index c7a5270e1..dbd2483a0 100644 --- a/test/unit/config.spec.js +++ b/test/unit/config.spec.js @@ -383,6 +383,15 @@ describe('config', () => { expect(invalid).to.throw('Invalid configuration: formatError option must be a function.') }) + + it('should prevent non-numeric input for numeric options', () => { + const invalid = function () { + normalizeConfigWithDefaults({ + pingTimeout: '10000' + }) + } + expect(invalid).to.throw('Invalid configuration: pingTimeout option must be a number.') + }) }) describe('createPatternObject', () => {