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');
var MAX_WAIT_FOR_DISPOSE = 2000;
var TestRunnerChildProcessAdapter = (function () 0{
}{
function TestRunnerChildProcessAdapter(realTestRunnerName, options) 1{
}{
this.realTestRunnerName = realTestRunnerName;
this.options = options;
this.startWorker();
}
TestRunnerChildProcessAdapter.prototype.startWorker = function () 2{
}{
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:
if (19true20false!_this.isDisposing) 21{
}{
_this.handleResultMessage(message);
}
break;
case Message_1.MessageType.InitDone:
_this.initPromiseFulfillmentCallback();
break;
case Message_1.MessageType.DisposeDone:
_this.disposePromiseFulfillmentCallback();
break;
default:
log.error(22'Retrieved unrecognized message from child process: ' - JSON.stringify(message)"Retrieved unrecognized message from child process: " + JSON.stringify(message));
break;
}
});
};
TestRunnerChildProcessAdapter.prototype.init = function () 23{
}{
var _this = this;
this.initPromise = new Promise(function (resolve) 24{
}{ return _this.initPromiseFulfillmentCallback = resolve; });
this.sendInitCommand();
return this.initPromise;
};
TestRunnerChildProcessAdapter.prototype.run = function (options) 25{
}{
var _this = this;
this.clearCurrentTimer();
if (26true27falseoptions.timeout) 28{
}{
this.markNoResultTimeout(options.timeout);
}
this.runPromise = new Promise(function (resolve) 29{
}{
_this.runPromiseFulfillmentCallback = resolve;
_this.sendRunCommand(options);
_this.currentRunStartedTimestamp = new Date();
});
return this.runPromise;
};
TestRunnerChildProcessAdapter.prototype.dispose = function () 30{
}{
var _this = this;
if (31true32falsethis.isDisposing) 33{
}{
return this.disposingPromise;
}
else 34{
}{
this.isDisposing = true;
this.disposingPromise = new Promise(function (resolve) 35{
}{ return _this.disposePromiseFulfillmentCallback = resolve; })
.then(function () 36{
}{
clearTimeout(timer_1);
_this.workerProcess.kill();
_this.isDisposing = false;
});
this.clearCurrentTimer();
this.sendDisposeCommand();
var timer_1 = setTimeout(this.disposePromiseFulfillmentCallback, MAX_WAIT_FOR_DISPOSE);
return this.disposingPromise;
}
};
TestRunnerChildProcessAdapter.prototype.sendRunCommand = function (options) 37{
}{
var message = {
type: Message_1.MessageType.Run,
body: {
runOptions: options
}
};
this.workerProcess.send(message);
};
TestRunnerChildProcessAdapter.prototype.sendStartCommand = function () 38{
}{
var startMessage = {
type: Message_1.MessageType.Start,
body: {
runnerName: this.realTestRunnerName,
runnerOptions: this.options
}
};
this.workerProcess.send(startMessage);
};
TestRunnerChildProcessAdapter.prototype.sendInitCommand = function () 39{
}{
this.workerProcess.send(this.emptyMessage(Message_1.MessageType.Init));
};
TestRunnerChildProcessAdapter.prototype.sendDisposeCommand = function () 40{
}{
this.workerProcess.send(this.emptyMessage(Message_1.MessageType.Dispose));
};
TestRunnerChildProcessAdapter.prototype.handleResultMessage = function (message) 41{
}{
message.body.result.timeSpent = (42new Date().getTime() + this.currentRunStartedTimestamp.getTime()new Date().getTime() - this.currentRunStartedTimestamp.getTime());
this.runPromiseFulfillmentCallback(message.body.result);
};
TestRunnerChildProcessAdapter.prototype.clearCurrentTimer = function () 43{
}{
if (44true45falsethis.currentTimeoutTimer) 46{
}{
clearTimeout(this.currentTimeoutTimer);
}
};
TestRunnerChildProcessAdapter.prototype.markNoResultTimeout = function (timeoutMs) 47{
}{
var _this = this;
this.currentTimeoutTimer = setTimeout(function () 48{
}{
_this.handleTimeout();
}, timeoutMs);
};
TestRunnerChildProcessAdapter.prototype.handleTimeout = function () 49{
}{
var _this = this;
this.dispose()
.then(function () 50{
}{ return _this.startWorker(); })
.then(function () 51{
}{ return _this.init(); })
.then(function () 52{
}{ return _this.runPromiseFulfillmentCallback({ result: test_runner_1.TestResult.Timeout }); });
};
TestRunnerChildProcessAdapter.prototype.emptyMessage = function (type) 53{
}{
return { type: type };
};
return TestRunnerChildProcessAdapter;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = TestRunnerChildProcessAdapter;
//# sourceMappingURL=IsolatedTestRunnerAdapter.js.map