diff options
Diffstat (limited to 'lib/grunt/utils.js')
| -rw-r--r-- | lib/grunt/utils.js | 22 | 
1 files changed, 20 insertions, 2 deletions
| diff --git a/lib/grunt/utils.js b/lib/grunt/utils.js index 90613a29..49d346a0 100644 --- a/lib/grunt/utils.js +++ b/lib/grunt/utils.js @@ -5,6 +5,22 @@ var spawn = require('child_process').spawn;  var version;  var CSP_CSS_HEADER = '/* Include this file in your html if you are using the CSP mode. */\n\n'; +var PORT_MIN = 8000; +var PORT_MAX = 9999; +var TRAVIS_BUILD_NUMBER = parseInt(process.env.TRAVIS_BUILD_NUMBER, 10); +var getRandomPorts = function() { +  if (!process.env.TRAVIS) { +    return [9876, 9877]; +  } + +  // Generate two numbers between PORT_MIN and PORT_MAX, based on TRAVIS_BUILD_NUMBER. +  return [ +    PORT_MIN + (TRAVIS_BUILD_NUMBER % (PORT_MAX - PORT_MIN)), +    PORT_MIN + ((TRAVIS_BUILD_NUMBER + 100) % (PORT_MAX - PORT_MIN)) +  ]; +}; + +  module.exports = {    init: function() { @@ -279,7 +295,7 @@ module.exports = {        stream: options && options.stream      }; -    args.push('--port=' + this.sauceLabsAvailablePorts.pop()); +    args.push('--port=' + this.availablePorts.pop());      if (args.indexOf('test:e2e') !== -1 && grunt.option('e2e-browsers')) {        args.push('--browsers=' + grunt.option('e2e-browsers')); @@ -295,5 +311,7 @@ module.exports = {    },    // see http://saucelabs.com/docs/connect#localhost -  sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876] +  sauceLabsAvailablePorts: [9000, 9001, 9080, 9090, 9876], +  // pseudo-random port numbers for BrowserStack +  availablePorts: getRandomPorts()  }; | 
