Summary
Code
"use strict";
var test_runner_1 = require('stryker-api/test_runner');
var child_process_1 = require('child_process');
var Message_1 = require('./Message');
var _ = require('lodash');
var log4js = require('log4js');
var log = log4js.getLogger('IsolatedTestRunnerAdapter');
/**
* Runs the given test runner in a child process and forwards reports about test results
* Also implements timeout-mechanisme (on timeout, restart the child runner and report timeout)
*/
var TestRunnerChildProcessAdapter = (function () 0{
}{
function TestRunnerChildProcessAdapter(realTestRunnerName, options) 1{
}{
this.realTestRunnerName = realTestRunnerName;
this.options = options;
this.startWorker();
}
TestRunnerChildProcessAdapter.prototype.startWorker = function () 2{
}{
// Remove --debug-brk from process arguments.
// When debugging, it will try to reuse the same debug port, which will be taken by the main process.
var execArgv = _.clone(process.execArgv);
_.remove(execArgv, function (arg) 3{
}{ return 4arg.substr(0, 11) !== '--debug-brk'arg.substr(0, 11) === '--debug-brk'; });
this.workerProcess = child_process_1.fork(5__dirname - '/IsolatedTestRunnerAdapterWorker'__dirname + "/IsolatedTestRunnerAdapterWorker", [], { silent: true, execArgv: execArgv });
this.sendStartCommand();
this.listenToWorkerProcess();
};
TestRunnerChildProcessAdapter.prototype.listenToWorkerProcess = function () 6{
}{
var _this = this;
if (7true8falsethis.workerProcess.stdout) 9{
}{
var traceEnabled_1 = log.isTraceEnabled();
this.workerProcess.stdout.on('data', function (data) 10{
}{
if (11true12falsetraceEnabled_1) 13{
}{
log.trace(data.toString());
}
});
}
if (14true15falsethis.workerProcess.stderr) 16{
}{
this.workerProcess.stderr.on('data', function (data) 17{
}{
log.error(data.toString());
});
}
this.workerProcess.on('message', function (message) 18{
}{
_this.clearCurrentTimer();
switch (message.type) {
case Message_1.MessageType.Result:
_this.handleResultMessage(message);
break;
default:
log.error(19'Retrieved unrecognized message from child process: ' - JSON.stringify(message)"Retrieved unrecognized message from child process: " + JSON.stringify(message));
break;
}
});
};
TestRunnerChildProcessAdapter.prototype.run = function (options) 20{
}{
var _this = this;
this.clearCurrentTimer();
if (21true22falseoptions.timeout) 23{
}{
this.markNoResultTimeout(options.timeout);
}
this.currentPromise = new Promise(function (resolve) 24{
}{
_this.currentPromiseFulfillmentCallback = resolve;
_this.sendRunCommand(options);
_this.currentRunStartedTimestamp = new Date();
});
return this.currentPromise;
};
TestRunnerChildProcessAdapter.prototype.dispose = function () 25{
}{
this.clearCurrentTimer();
this.workerProcess.kill();
};
TestRunnerChildProcessAdapter.prototype.sendRunCommand = function (options) 26{
}{
var message = {
type: Message_1.MessageType.Run,
body: {
runOptions: options
}
};
this.workerProcess.send(message);
};
TestRunnerChildProcessAdapter.prototype.sendStartCommand = function () 27{
}{
var startMessage = {
type: Message_1.MessageType.Start,
body: {
runnerName: this.realTestRunnerName,
runnerOptions: this.options
}
};
this.workerProcess.send(startMessage);
};
TestRunnerChildProcessAdapter.prototype.handleResultMessage = function (message) 28{
}{
message.body.result.timeSpent = (29new Date().getTime() + this.currentRunStartedTimestamp.getTime()new Date().getTime() - this.currentRunStartedTimestamp.getTime());
this.currentPromiseFulfillmentCallback(message.body.result);
};
TestRunnerChildProcessAdapter.prototype.clearCurrentTimer = function () 30{
}{
if (31true32falsethis.currentTimeoutTimer) 33{
}{
clearTimeout(this.currentTimeoutTimer);
}
};
TestRunnerChildProcessAdapter.prototype.markNoResultTimeout = function (timeoutMs) 34{
}{
var _this = this;
this.currentTimeoutTimer = setTimeout(function () 35{
}{
_this.handleTimeout();
}, timeoutMs);
};
TestRunnerChildProcessAdapter.prototype.handleTimeout = function () 36{
}{
this.workerProcess.kill();
this.startWorker();
this.currentPromiseFulfillmentCallback({ result: test_runner_1.TestResult.Timeout });
};
return TestRunnerChildProcessAdapter;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = TestRunnerChildProcessAdapter;
//# sourceMappingURL=IsolatedTestRunnerAdapter.js.map