Summary
File |
Based on all code |
Based on code coverage |
Stryker.js |
|
62/62 |
100% |
62/62 |
Code
'use strict';
var _ = require('lodash');
var MutatorOrchestrator_1 = require('./MutatorOrchestrator');
var config_1 = require('stryker-api/config');
var TestRunnerOrchestrator_1 = require('./TestRunnerOrchestrator');
var ReporterOrchestrator_1 = require('./ReporterOrchestrator');
require('./jasmine_test_selector/JasmineTestSelector');
var test_runner_1 = require('stryker-api/test_runner');
var TestSelectorOrchestrator_1 = require('./TestSelectorOrchestrator');
var MutantRunResultMatcher_1 = require('./MutantRunResultMatcher');
var InputFileResolver_1 = require('./InputFileResolver');
var ConfigReader_1 = require('./ConfigReader');
var PluginLoader_1 = require('./PluginLoader');
var objectUtils_1 = require('./utils/objectUtils');
var log4js = require('log4js');
var log = log4js.getLogger('Stryker');
var Stryker = (function () 0{
}{
/**
* 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) 1{
}{
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();
}
/**
* Runs mutation testing. This may take a while.
* @function
*/
Stryker.prototype.runMutationTest = function () 2{
}{
var _this = this;
var reporter = new ReporterOrchestrator_1.default(this.config).createBroadcastReporter();
var testSelector = new TestSelectorOrchestrator_1.default(this.config).determineTestSelector();
return new InputFileResolver_1.default(this.config.mutate, this.config.files).resolve()
.then(function (inputFiles) 3{
}{
var testRunnerOrchestrator = new TestRunnerOrchestrator_1.default(_this.config, inputFiles, testSelector, reporter);
return testRunnerOrchestrator.initialRun().then(function (runResults) 4{
}{ return ({ runResults: runResults, inputFiles: inputFiles, testRunnerOrchestrator: testRunnerOrchestrator }); });
})
.then(function (tuple) 5{
}{
var runResults = tuple.runResults;
var inputFiles = tuple.inputFiles;
var testRunnerOrchestrator = tuple.testRunnerOrchestrator;
var unsuccessfulTests = _this.filterOutUnsuccesfulResults(runResults);
if (6false7unsuccessfulTests.length !== 08trueunsuccessfulTests.length === 0) 9{
}{
_this.logInitialTestRunSucceeded(runResults);
var mutatorOrchestrator = new MutatorOrchestrator_1.default(reporter);
var mutants = mutatorOrchestrator.generateMutants(inputFiles
.filter(function (inputFile) 10{
}{ return inputFile.shouldMutate; })
.map(function (file) 11{
}{ return file.path; }));
log.info(12mutants.length - ' Mutant(s) generated'mutants.length + " Mutant(s) generated");
var mutantRunResultMatcher = new MutantRunResultMatcher_1.default(mutants, runResults);
mutantRunResultMatcher.matchWithMutants();
return testRunnerOrchestrator.runMutations(mutants);
}
else 13{
}{
_this.logFailedTests(unsuccessfulTests);
throw new Error('There were failed tests in the initial test run');
}
}).then(function (mutantResults) 14{
}{
var maybePromise = reporter.wrapUp();
if (15true16falseobjectUtils_1.isPromise(maybePromise)) 17{
}{
return maybePromise.then(function () 18{
}{ return mutantResults; });
}
else 19{
}{
return mutantResults;
}
});
};
Stryker.prototype.filterOutUnsuccesfulResults = function (runResults) 20{
}{
return runResults.filter(function (runResult) 21{
}{ return !(22!runResult.failed || runResult.result === test_runner_1.TestResult.Complete!runResult.failed && 23runResult.result !== test_runner_1.TestResult.CompleterunResult.result === test_runner_1.TestResult.Complete); });
};
Stryker.prototype.loadPlugins = function () 24{
}{
if (25true26falsethis.config.plugins) 27{
}{
new PluginLoader_1.default(this.config.plugins).load();
}
};
Stryker.prototype.applyConfigWriters = function () 28{
}{
var _this = this;
config_1.ConfigWriterFactory.instance().knownNames().forEach(function (configWriterName) 29{
}{
config_1.ConfigWriterFactory.instance().create(configWriterName, undefined).write(_this.config);
});
};
Stryker.prototype.freezeConfig = function () 30{
}{
objectUtils_1.freezeRecursively(this.config);
if (31true32falselog.isDebugEnabled()) 33{
}{
log.debug(34'Using config: ' - JSON.stringify(this.config)"Using config: " + JSON.stringify(this.config));
}
};
Stryker.prototype.logInitialTestRunSucceeded = function (runResults) 35{
}{
var totalAmountOfTests = 0;
runResults.forEach(function (result) 36{
}{
if (37true38falseresult.succeeded) 39{
}{
totalAmountOfTests += result.succeeded;
}
});
log.info('Initial test run succeeded. Ran %s tests.', totalAmountOfTests);
};
Stryker.prototype.setGlobalLogLevel = function () 40{
}{
log4js.setGlobalLogLevel(this.config.logLevel);
};
/**
* Looks through a list of RunResults to see if all tests have passed.
* @function
* @param {RunResult[]} runResults - The list of RunResults.
* @returns {Boolean} True if all tests passed.
*/
Stryker.prototype.logFailedTests = function (unsuccessfulTests) 41{
}{
var failedSpecNames = _.uniq(_.flatten(unsuccessfulTests
.filter(function (runResult) 42{
}{ return 43runResult.result !== test_runner_1.TestResult.CompleterunResult.result === test_runner_1.TestResult.Complete; })
.map(function (runResult) 44{
}{ return runResult.testNames; })))
.sort();
if (45failedSpecNames.length <= 046failedSpecNames.length >= 047false48truefailedSpecNames.length > 0) 49{
}{
var message_1 = 'One or more tests failed in the inial test run:';
failedSpecNames.forEach(function (filename) 50{
}{ return message_1 += 51'\n\t' - filename"\n\t" + filename; });
log.error(message_1);
}
var errors = _.flatten(unsuccessfulTests
.filter(function (runResult) 52{
}{ return 53runResult.result !== test_runner_1.TestResult.ErrorrunResult.result === test_runner_1.TestResult.Error; })
.map(function (runResult) 54{
}{ return runResult.errorMessages; }))
.sort();
if (55errors.length <= 056errors.length >= 057true58falseerrors.length > 0) 59{
}{
var message_2 = 'One or more tests errored in the initial test run:';
errors.forEach(function (error) 60{
}{ return message_2 += 61'\n\t' - error"\n\t" + error; });
log.error(message_2);
}
};
return Stryker;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = Stryker;
//# sourceMappingURL=Stryker.js.map