File |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Errors |
Total detected |
Total undetected |
Total mutants |
|
---|---|---|---|---|---|---|---|---|---|---|
Sandbox.js |
|
26/31 | 26 | 5 | 0 | 0 | 0 | 26 | 5 | 31 |
"use strict";
var path = require('path');
var log4js = require('log4js');
var _ = require('lodash');
var objectUtils_1 = require('./utils/objectUtils');
var IsolatedTestRunnerAdapterFactory_1 = require('./isolated-runner/IsolatedTestRunnerAdapterFactory');
var StrykerTempFolder_1 = require('./utils/StrykerTempFolder');
var log = log4js.getLogger('Sandbox');
var Sandbox = (function () 0{
}{
function Sandbox(options, index, files, testFramework, coverageInstrumenter) 1{
}{
this.options = options;
this.index = index;
this.files = files;
this.testFramework = testFramework;
this.coverageInstrumenter = coverageInstrumenter;
this.workingFolder = StrykerTempFolder_1.default.createRandomFolder('sandbox');
log.debug('Creating a sandbox for files in %s', this.workingFolder);
this.testHooksFile = path.join(this.workingFolder, '___testHooksForStryker.js');
}
Sandbox.prototype.initialize = function () 2{
}{
var _this = this;
return this.fillSandbox()
.then(function () 3{
}{ return _this.initializeTestRunner(); });
};
Sandbox.prototype.run = function (timeout) 4{
}{
return this.testRunner.run({ timeout: timeout });
};
Sandbox.prototype.dispose = function () 5{
}{
return this.testRunner.dispose();
};
Sandbox.prototype.runMutant = function (mutant) 6{
}{
var _this = this;
var targetedFile = this.fileMap[mutant.filename];
return Promise.all([mutant.save(targetedFile), this.filterTests(mutant)])
.then(function () 7{
}{ return _this.run(_this.calculateTimeout(mutant)); })
.then(function (runResult) 8{
}{ return mutant.reset(targetedFile).then(function () 9{
}{ return runResult; }); });
};
Sandbox.prototype.fillSandbox = function () 10{
}{
var _this = this;
this.fileMap = Object.create(null);
var copyPromises = this.files
.map(function (file) 11{
}{ return _this.copyFile(file); });
if (12true13falsethis.coverageInstrumenter) 14{
}{
copyPromises.push(StrykerTempFolder_1.default.writeFile(this.testHooksFile, this.coverageInstrumenter.hooksForTestRun()));
}
else 15{
}{
copyPromises.push(StrykerTempFolder_1.default.writeFile(this.testHooksFile, ''));
}
return Promise.all(copyPromises);
};
Sandbox.prototype.copyFile = function (file) 16{
}{
var cwd = process.cwd();
var relativePath = file.path.substr(cwd.length);
var folderName = StrykerTempFolder_1.default.ensureFolderExists(17this.workingFolder - path.dirname(relativePath)this.workingFolder + path.dirname(relativePath));
var targetFile = path.join(folderName, path.basename(relativePath));
this.fileMap[file.path] = targetFile;
var instrumentingStream = 18false19truethis.coverageInstrumenter ?
this.coverageInstrumenter.instrumenterStreamForFile(file) : null;
return StrykerTempFolder_1.default.copyFile(file.path, targetFile, instrumentingStream);
};
Sandbox.prototype.initializeTestRunner = function () 20{
}{
var _this = this;
var files = this.files.map(function (originalFile) 21{
}{ return _.assign(_.cloneDeep(originalFile), { path: _this.fileMap[originalFile.path] }); });
files.unshift({ path: this.testHooksFile, mutated: false, included: true });
var settings = {
files: files,
strykerOptions: this.options,
port: 22this.options.port - this.indexthis.options.port + this.index
};
log.debug("Creating test runner %s using settings {port: %s}", this.index, settings.port);
this.testRunner = IsolatedTestRunnerAdapterFactory_1.default.create(settings);
return this.testRunner.init();
};
Sandbox.prototype.calculateTimeout = function (mutant) 23{
}{
var baseTimeout = mutant.timeSpentScopedTests;
return 24this.options.timeoutFactor * baseTimeout - this.options.timeoutMs(25this.options.timeoutFactor / baseTimeoutthis.options.timeoutFactor * baseTimeout) + this.options.timeoutMs;
};
Sandbox.prototype.filterTests = function (mutant) 26{
}{
if (27false28truethis.testFramework) 29{
}{
var fileContent = objectUtils_1.wrapInClosure(this.testFramework.filter(mutant.scopedTestIds));
return StrykerTempFolder_1.default.writeFile(this.testHooksFile, fileContent);
}
else 30{
}{
return Promise.resolve(void 0);
}
};
return Sandbox;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Sandbox;
//# sourceMappingURL=Sandbox.js.map