lib/karma/KarmaServerManager.js
function startServer(serverPromise) {
    var self = this,
        startTime = Date.now(),
        browsersStarting,
        serverTimeout,
        serverProcess = fork(__dirname + '/KarmaWorker.js', { silent: true });

    // Limit the time it can take for a server to start to config.waitForServerTime seconds
    serverTimeout = setTimeout(function() {
        self._setStatus(KarmaServerStatus.DEFUNCT);
        serverPromise.reject(
            'Could not connect to a Karma server on port ' + self._config.port + ' within ' +
            self._config.waitForServerTime + ' seconds'
        );
    }, self._config.waitForServerTime * 1000);

    serverProcess.send({ command: 'start', config: self._config });

    serverProcess.stdout.on('data', function(data) {
        var message = data.toString('utf-8'),
            messageParts = message.split(/\s/g);

        logger.debug(message);

        //this is a hack: because Karma exposes no method of determining when the server is started up we'll dissect the log messages
        if(message.indexOf('Starting browser') > -1) {
            browsersStarting = browsersStarting ? browsersStarting.concat([messageParts[4]]) : [messageParts[4]];
        }
        if(message.indexOf('Connected on socket') > -1) {
            browsersStarting.pop();
            if(browsersStarting && browsersStarting.length === 0) {
                clearTimeout(serverTimeout);
                self._setStatus(KarmaServerStatus.READY);

                logger.info(
                    'Karma server started after %dms and is listening on port %d',
                    (Date.now() - startTime), self._config.port
                );

                serverPromise.resolve(self);
            }
        }
    });

    return serverProcess;
}
function startServer(serverPromise) {
    var self = this,
        startTime = Date.now(),
        browsersStarting,
        serverTimeout,
        serverProcess = fork(__dirname + '/KarmaWorker.js', { silent: true });

    // Limit the time it can take for a server to start to config.waitForServerTime seconds
    serverTimeout = setTimeout(function() {
        self._setStatus(KarmaServerStatus.DEFUNCT);
        serverPromise.reject(
            'Could not connect to a Karma server on port ' + self._config.port + ' within ' +
            self._config.waitForServerTime + ' seconds'
        );
    }, self._config.waitForServerTime * 1000);

    serverProcess.send({ command: 'start', config: self._config });

    serverProcess.stdout.on('data', function(data) {
        var message = data.toString('utf-8'),
            messageParts = message.split(/\s/g);

        logger.debug(message);

        //this is a hack: because Karma exposes no method of determining when the server is started up we'll dissect the log messages
        if(message.indexOf('Starting browser') > -1) {
            browsersStarting = browsersStarting ? browsersStarting.concat([messageParts[4]]) : [messageParts[4]];
        }
        if(message.indexOf('Connected on socket') > -1) {
            browsersStarting.pop();
            if(browsersStarting && browsersStarting.length === 0) {
                clearTimeout(serverTimeout);
                self._setStatus(KarmaServerStatus.READY);

                logger.info(
                    'Karma server started after %dms and is listening on port %d',
                    (Date.now() - startTime), self._config.port
                );

                serverPromise.resolve(self);
            }
        }
    });

    return serverProcess;
}
function startServer ( serverPromise ) { var self = this , startTime = Date . now ( ) , browsersStarting , serverTimeout , serverProcess = fork ( __dirname + '/KarmaWorker.js' , { silent : true } ) ; // Limit the time it can take for a server to start to config.waitForServerTime seconds serverTimeout = setTimeout ( function ( ) { self . _setStatus ( KarmaServerStatus . DEFUNCT ) ; serverPromise . reject ( 'Could not connect to a Karma server on port ' + self . _config . port + ' within ' + self . _config . waitForServerTime + ' seconds' ) ; } , self . _config . waitForServerTime * 1000 ) ; serverProcess . send ( { command : 'start' , config : self . _config } ) ; serverProcess . stdout . on ( 'data' , function ( data ) { var message = data . toString ( 'utf-8' ) , messageParts = message . split ( / \s / g ) ; logger . debug ( message ) ; //this is a hack: because Karma exposes no method of determining when the server is started up we'll dissect the log messages if ( message . indexOf ( 'Starting browser' ) > - 1 ) { browsersStarting = browsersStarting ? browsersStarting . concat ( [ messageParts [ 4 ] ] ) : [ messageParts [ 4 ] ] ; } if ( message . indexOf ( 'Connected on socket' ) > - 1 ) { browsersStarting . pop ( ) ; if ( browsersStarting && browsersStarting . length === 0 ) { clearTimeout ( serverTimeout ) ; self . _setStatus ( KarmaServerStatus . READY ) ; logger . info ( 'Karma server started after %dms and is listening on port %d' , ( Date . now ( ) - startTime ) , self . _config . port ) ; serverPromise . resolve ( self ) ; } } } ) ; return serverProcess ; }
start a karma server by calling node's "fork" method.
The stdio will be piped to the current process so that it can be read and interpreted
start a karma server by calling node s fork method . The stdio will be piped to the current process so that it can be read and interpreted