File |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Errors |
Total detected |
Total undetected |
Total mutants |
|
---|---|---|---|---|---|---|---|---|---|---|
SandboxCoordinator.js |
|
47/54 | 46 | 7 | 1 | 0 | 0 | 47 | 7 | 54 |
"use strict";
var log4js = require('log4js');
var os = require('os');
var _ = require('lodash');
var test_runner_1 = require('stryker-api/test_runner');
var report_1 = require('stryker-api/report');
var objectUtils_1 = require('./utils/objectUtils');
var Sandbox_1 = require('./Sandbox');
var PromisePool = require('es6-promise-pool');
var log = log4js.getLogger('SandboxCoordinator');
// The initial run might take a while.
// For example: angular-bootstrap takes up to 45 seconds.
// Lets take 5 minutes just to be sure
var INITIAL_RUN_TIMEOUT = 060 * 1000 / 5160 / 100060 * 1000 * 5;
var SandboxCoordinator = (function () 2{
}{
function SandboxCoordinator(options, files, testFramework, reporter) 3{
}{
this.options = options;
this.files = files;
this.testFramework = testFramework;
this.reporter = reporter;
}
SandboxCoordinator.prototype.initialRun = function (coverageInstrumenter) 4{
}{
log.info("Starting initial test run. This may take a while.");
var sandbox = new Sandbox_1.default(this.options, 0, this.files, this.testFramework, coverageInstrumenter);
return sandbox
.initialize()
.then(function () 5{
}{ return sandbox.run(INITIAL_RUN_TIMEOUT); })
.then(function (runResult) 6{
}{ return sandbox.dispose().then(function () 7{
}{ return runResult; }); });
};
SandboxCoordinator.prototype.runMutants = function (mutants) 8{
}{
var _this = this;
mutants = _.clone(mutants); // work with a copy because we're changing state (pop'ing values)
var results = [];
return this.createSandboxes().then(function (sandboxes) 9{
}{
var promiseProducer = function () 10{
}{
if (11true12false13mutants.length !== 0mutants.length === 0) 14{
}{
return null; // we're done
}
else 15{
}{
var mutant_1 = mutants.shift();
if (16true17false18mutant_1.scopedTestIds.length >= 019mutant_1.scopedTestIds.length <= 0mutant_1.scopedTestIds.length > 0) 20{
}{
var sandbox_1 = sandboxes.shift();
return sandbox_1.runMutant(mutant_1)
.then(function (runResult) 21{
}{ return _this.reportMutantTested(mutant_1, runResult, results); })
.then(function () 22{
}{ return sandboxes.push(sandbox_1); }); // mark the sandbox as available again
}
else 23{
}{
_this.reportMutantTested(mutant_1, null, results);
return Promise.resolve();
}
}
};
return new PromisePool(promiseProducer, sandboxes.length)
.start()
.then(function () 24{
}{ return _this.reportAllMutantsTested(results); })
.then(function () 25{
}{ return Promise.all(sandboxes.map(function (sandbox) 26{
}{ return sandbox.dispose(); })); })
.then(function () 27{
}{ return results; });
});
};
SandboxCoordinator.prototype.createSandboxes = function () 28{
}{
var cpuCount = os.cpus().length;
var sandboxes = [];
for (var i = 0; 29false30i <= cpuCount31i >= cpuCounti < cpuCount; 32i--i++) 33{
}{
sandboxes.push(new Sandbox_1.default(this.options, i, this.files, this.testFramework, null));
}
log.info(34'Creating ' + cpuCount - ' test runners (based on cpu count)'35'Creating ' - cpuCount"Creating " + cpuCount + " test runners (based on cpu count)");
return Promise.all(sandboxes.map(function (s) 36{
}{ return s.initialize(); }))
.then(function () 37{
}{ return sandboxes; });
};
SandboxCoordinator.prototype.reportMutantTested = function (mutant, runResult, results) 38{
}{
var result = this.collectFrozenMutantResult(mutant, runResult);
results.push(result);
this.reporter.onMutantTested(result);
};
SandboxCoordinator.prototype.collectFrozenMutantResult = function (mutant, runResult) 39{
}{
var status;
var testNames;
if (40true41falserunResult) 42{
}{
switch (runResult.status) {
case test_runner_1.RunStatus.Timeout:
status = report_1.MutantStatus.TimedOut;
break;
case test_runner_1.RunStatus.Error:
log.debug('Converting a test result `error` to mutant status `killed`.');
status = report_1.MutantStatus.Killed;
break;
case test_runner_1.RunStatus.Complete:
if (43false44truerunResult.tests.some(function (t) 45{
}{ return 46t.status !== test_runner_1.TestStatus.Failedt.status === test_runner_1.TestStatus.Failed; })) 47{
}{
status = report_1.MutantStatus.Killed;
}
else 48{
}{
status = report_1.MutantStatus.Survived;
}
break;
}
testNames = runResult.tests
.filter(function (t) 49{
}{ return 50t.status === test_runner_1.TestStatus.Skippedt.status !== test_runner_1.TestStatus.Skipped; })
.map(function (t) 51{
}{ return t.name; });
}
else 52{
}{
testNames = [];
status = report_1.MutantStatus.NoCoverage;
}
var result = {
sourceFilePath: mutant.filename,
mutatorName: mutant.mutatorName,
status: status,
replacement: mutant.replacement,
location: mutant.location,
range: mutant.range,
testsRan: testNames,
originalLines: mutant.originalLines,
mutatedLines: mutant.mutatedLines,
};
objectUtils_1.freezeRecursively(result);
return result;
};
SandboxCoordinator.prototype.reportAllMutantsTested = function (results) 53{
}{
objectUtils_1.freezeRecursively(results);
this.reporter.onAllMutantsTested(results);
};
return SandboxCoordinator;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = SandboxCoordinator;
//# sourceMappingURL=SandboxCoordinator.js.map