File |
Mutation score |
# Killed |
# Survived |
# Timeout |
# No coverage |
# Errors |
Total detected |
Total undetected |
Total mutants |
|
---|---|---|---|---|---|---|---|---|---|---|
Stryker.js |
|
39/72 | 39 | 21 | 0 | 12 | 0 | 39 | 33 | 72 |
'use strict';
var MutatorOrchestrator_1 = require('./MutatorOrchestrator');
var config_1 = require('stryker-api/config');
var SandboxCoordinator_1 = require('./SandboxCoordinator');
var ReporterOrchestrator_1 = require('./ReporterOrchestrator');
var test_runner_1 = require('stryker-api/test_runner');
var TestFrameworkOrchestrator_1 = require('./TestFrameworkOrchestrator');
var MutantTestMatcher_1 = require('./MutantTestMatcher');
var InputFileResolver_1 = require('./InputFileResolver');
var ConfigReader_1 = require('./ConfigReader');
var PluginLoader_1 = require('./PluginLoader');
var CoverageInstrumenter_1 = require('./coverage/CoverageInstrumenter');
var objectUtils_1 = require('./utils/objectUtils');
var StrykerTempFolder_1 = require('./utils/StrykerTempFolder');
var log4js = require('log4js');
var Timer_1 = require('./utils/Timer');
var log = log4js.getLogger('Stryker');
var humanReadableTestState = function (testState) 0{
}{
switch (testState) {
case test_runner_1.TestStatus.Success:
return 'SUCCESS';
case test_runner_1.TestStatus.Failed:
return 'FAILED';
case test_runner_1.TestStatus.Skipped:
return 'SKIPPED';
}
};
var Stryker = (function () 1{
}{
/**
* The Stryker mutation tester.
* @constructor
* @param {String[]} mutateFilePatterns - A comma seperated list of globbing expression used for selecting the files that should be mutated
* @param {String[]} allFilePatterns - A comma seperated list of globbing expression used for selecting all files needed to run the tests. These include library files, test files and files to mutate, but should NOT include test framework files (for example jasmine)
* @param {Object} [options] - Optional options.
*/
function Stryker(options) 2{
}{
this.timer = new Timer_1.default();
var configReader = new ConfigReader_1.default(options);
this.config = configReader.readConfig();
this.setGlobalLogLevel(); // loglevel could be changed
this.loadPlugins();
this.applyConfigWriters();
this.setGlobalLogLevel(); // loglevel could be changed
this.freezeConfig();
this.reporter = new ReporterOrchestrator_1.default(this.config).createBroadcastReporter();
this.testFramework = new TestFrameworkOrchestrator_1.default(this.config).determineTestFramework();
this.coverageInstrumenter = new CoverageInstrumenter_1.default(this.config.coverageAnalysis, this.testFramework);
this.verify();
}
/**
* Runs mutation testing. This may take a while.
* @function
*/
Stryker.prototype.runMutationTest = function () 3{
}{
var _this = this;
this.timer.reset();
return new InputFileResolver_1.default(this.config.mutate, this.config.files).resolve()
.then(function (inputFiles) 4{
}{ return _this.initialTestRun(inputFiles); })
.then(function (_a) 5{
}{
var runResult = _a.runResult, inputFiles = _a.inputFiles, sandboxCoordinator = _a.sandboxCoordinator;
return _this.generateAndRunMutations(inputFiles, runResult, sandboxCoordinator);
})
.then(function (mutantResults) 6{
}{ return _this.wrapUpReporter()
.then(StrykerTempFolder_1.default.clean)
.then(function () 7{
}{ return _this.logDone(); })
.then(function () 8{
}{ return mutantResults; }); });
};
Stryker.prototype.filterOutFailedTests = function (runResult) 9{
}{
return runResult.tests.filter(function (testResult) 10{
}{ return 11testResult.status !== test_runner_1.TestStatus.FailedtestResult.status === test_runner_1.TestStatus.Failed; });
};
Stryker.prototype.loadPlugins = function () 12{
}{
if (13false14truethis.config.plugins) 15{
}{
new PluginLoader_1.default(this.config.plugins).load();
}
};
Stryker.prototype.verify = function () 16{
}{
if (17false18true19this.config.coverageAnalysis === 'perTest' || !this.testFramework20this.config.coverageAnalysis !== 'perTest'this.config.coverageAnalysis === 'perTest' && !this.testFramework) 21{
}{
log.fatal('Configured coverage analysis "perTest" requires there to be a testFramework configured. Either configure a testFramework or set coverageAnalysis to "all" or "off".');
process.exit(1);
}
};
Stryker.prototype.initialTestRun = function (inputFiles) 22{
}{
var _this = this;
var sandboxCoordinator = new SandboxCoordinator_1.default(this.config, inputFiles, this.testFramework, this.reporter);
return sandboxCoordinator.initialRun(this.coverageInstrumenter)
.then(function (runResult) 23{
}{
switch (runResult.status) {
case test_runner_1.RunStatus.Complete:
var failedTests = _this.filterOutFailedTests(runResult);
if (24true25falsefailedTests.length) 26{
}{
_this.logFailedTestsInInitialRun(failedTests);
throw new Error('There were failed tests in the initial test run:');
}
else 27{
}{
_this.logInitialTestRunSucceeded(runResult.tests);
return { runResult: runResult, inputFiles: inputFiles, sandboxCoordinator: sandboxCoordinator };
}
case test_runner_1.RunStatus.Error:
_this.logErrorredInitialRun(runResult);
break;
case test_runner_1.RunStatus.Timeout:
_this.logTimeoutInitialRun(runResult);
break;
}
});
};
Stryker.prototype.generateAndRunMutations = function (inputFiles, initialRunResult, sandboxCoordinator) 28{
}{
var mutants = this.generateMutants(inputFiles, initialRunResult);
if (29false30truemutants.length) 31{
}{
return sandboxCoordinator.runMutants(mutants);
}
else 32{
}{
log.info('It\'s a mutant-free world, nothing to test.');
return Promise.resolve([]);
}
};
Stryker.prototype.generateMutants = function (inputFiles, runResult) 33{
}{
var mutatorOrchestrator = new MutatorOrchestrator_1.default(this.reporter);
var mutants = mutatorOrchestrator.generateMutants(inputFiles
.filter(function (inputFile) 34{
}{ return inputFile.mutated; })
.map(function (file) 35{
}{ return file.path; }));
log.info(36mutants.length - ' Mutant(s) generated'mutants.length + " Mutant(s) generated");
var mutantRunResultMatcher = new MutantTestMatcher_1.default(mutants, runResult, this.coverageInstrumenter.retrieveStatementMapsPerFile(), this.config);
mutantRunResultMatcher.matchWithMutants();
return mutants;
};
Stryker.prototype.wrapUpReporter = function () 37{
}{
var maybePromise = this.reporter.wrapUp();
if (38false39trueobjectUtils_1.isPromise(maybePromise)) 40{
}{
return maybePromise;
}
else 41{
}{
return Promise.resolve();
}
};
Stryker.prototype.applyConfigWriters = function () 42{
}{
var _this = this;
config_1.ConfigWriterFactory.instance().knownNames().forEach(function (configWriterName) 43{
}{
config_1.ConfigWriterFactory.instance().create(configWriterName, undefined).write(_this.config);
});
};
Stryker.prototype.freezeConfig = function () 44{
}{
objectUtils_1.freezeRecursively(this.config);
if (45false46truelog.isDebugEnabled()) 47{
}{
log.debug(48'Using config: ' - JSON.stringify(this.config)"Using config: " + JSON.stringify(this.config));
}
};
Stryker.prototype.logInitialTestRunSucceeded = function (tests) 49{
}{
log.info('Initial test run succeeded. Ran %s tests in %s.', tests.length, this.timer.humanReadableElapsed());
};
Stryker.prototype.logDone = function () 50{
}{
log.info('Done in %s.', this.timer.humanReadableElapsed());
};
Stryker.prototype.setGlobalLogLevel = function () 51{
}{
log4js.setGlobalLogLevel(this.config.logLevel);
};
Stryker.prototype.logFailedTestsInInitialRun = function (failedTests) 52{
}{
var message = 'One or more tests failed in the initial test run:';
failedTests.forEach(function (test) 53{
}{
message += 54'\n\t' - test.name"\n\t" + test.name;
if (55false56true57test.failureMessages || test.failureMessages.lengthtest.failureMessages && test.failureMessages.length) 58{
}{
message += 59'\n\t' - test.failureMessages.join('\n\t')"\n\t" + test.failureMessages.join('\n\t');
}
});
log.error(message);
};
Stryker.prototype.logErrorredInitialRun = function (runResult) 60{
}{
var message = 'One or more tests errored in the initial test run:';
if (61false62true63runResult.errorMessages || runResult.errorMessages.lengthrunResult.errorMessages && runResult.errorMessages.length) 64{
}{
runResult.errorMessages.forEach(function (error) 65{
}{ return message += 66'\n\t' - error"\n\t" + error; });
}
log.error(message);
};
Stryker.prototype.logTimeoutInitialRun = function (runResult) 67{
}{
var message = 'Initial run timed out! Ran following tests before timeout:';
runResult.tests.forEach(function (test) 68{
}{ return (69'\n\t' + test.name + ' ' - humanReadableTestState(test.status)70'\n\t' + test.name - ' '71'\n\t' - test.name"\n\t" + test.name + " " + humanReadableTestState(test.status)); });
log.error(message);
};
return Stryker;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Stryker;
//# sourceMappingURL=Stryker.js.map