# Code coverage report for lib/highlight/client.js

## Statements: 91.67% (22 / 24) Branches: 75% (3 / 4) Functions: 75% (3 / 4) Lines: 90.91% (20 / 22) Ignored: none

All files » lib/highlight/ » client.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    311
    1
    1
    1

    1
    1
    1
    2

    1
    1
    2
    2
    2
    2
    2
    2

    1

    1

    1
    10
     var fork = require('child_process').fork;
    var path = require('path');
    var minimist = require('rc/node_modules/minimist');
    var Promise = require('bluebird');

    var init = Promise.resolve();
    var opts = minimist(process.execArgv);
    var forkOpts = {silent: false};
    Iif (['debug', 'debug-brk'].some(function (opt) { return opt in opts; })) {
      init = init
    	  .then(require('get-random-port'))
    	  .then(function (port) { forkOpts.execArgv = ['--debug=' + port]; });
    }

    var client;
    function initClient () {
      var oldMessageListeners = client ? client.listeners('message') : [];
      client = fork(path.join(__dirname, 'server.js'), forkOpts);
      client.setMaxListeners(100);
      client.on('exit', initClient);
      oldMessageListeners.forEach(client.on.bind(client, 'message'));
      return client;
    }

    init = init.then(initClient);

    module.exports = init;

    var buckets = 0;
    module.exports.getBucket = function () { return buckets++; };