/**
 * Run karma test.
 * @function task.worker.runKarmaTest
 * @param {object} config - Task configuration.
 * @param {string} config.karmaConfigFile - Karma config file path.
 * @param {function} callback - Callback when done.
 * @author Taka Okunishi
 */
var path = require('path'),
    childProcess = require('child_process'),
    fork = childProcess.fork;

module.exports = function (config, callback) {
    var karma = require('karma'),
        karmaConfigFile = path.resolve(config.karmaConfigFile);
    var server = fork(require.resolve('./.private/_karma_server'), [karmaConfigFile]);
    server.on('message', function () {
        server.send({kill: true});
        callback();
    });
};