stryker
Version:
The extendable JavaScript mutation testing framework
88 lines • 5.3 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
var program = require("commander");
var ConfigReader_1 = require("./config/ConfigReader");
var Stryker_1 = require("./Stryker");
var log4js_1 = require("log4js");
var LogConfigurator_1 = require("./logging/LogConfigurator");
var initializer_1 = require("./initializer");
var StrykerCli = /** @class */ (function () {
function StrykerCli(argv) {
this.argv = argv;
this.command = '';
this.strykerConfig = null;
}
StrykerCli.prototype.list = function (val) {
return val.split(',');
};
StrykerCli.prototype.run = function () {
var _this = this;
program
.version(require('../package.json').version)
.usage('<command> [options] [stryker.conf.js]')
.description("Possible commands:\n run: Run mutation testing\n init: Initialize Stryker for your project\n\n Optional location to the stryker.conf.js file as last argument. That file should export a function which accepts a \"config\" object\n" + ConfigReader_1.CONFIG_SYNTAX_HELP)
.arguments('<command> [stryker.conf.js]')
.action(function (cmd, config) {
_this.command = cmd;
_this.strykerConfig = config;
})
.option('-f, --files <allFiles>', "A comma separated list of globbing expression used for selecting all files needed to run the tests. For a more detailed way of selecting inputfiles, please use a configFile.\n Example: node_modules/a-lib/**/*.js,src/**/*.js,!src/index.js,a.js,test/**/*.js", this.list)
.option('-m, --mutate <filesToMutate>', "A comma separated list of globbing expression used for selecting the files that should be mutated.\n Example: src/**/*.js,a.js", this.list)
.option('--coverageAnalysis <perTest|all|off>', "The coverage analysis strategy you want to use. Default value: \"perTest\"")
.option('--testFramework <name>', "The name of the test framework you want to use.")
.option('--testRunner <name>', "The name of the test runner you want to use")
.option('--mutator <name>', "The name of the mutant generator you want to use")
.option('--transpilers <listOfTranspilers>', 'A comma separated list of transpilers to use.', this.list)
.option('--reporters <name>', 'A comma separated list of the names of the reporter(s) you want to use', this.list)
.option('--plugins <listOfPlugins>', 'A list of plugins you want stryker to load (`require`).', this.list)
.option('--timeoutMS <number>', 'Tweak the absolute timeout used to wait for a test runner to complete', parseInt)
.option('--timeoutFactor <number>', 'Tweak the standard deviation relative to the normal test run of a mutated test', parseFloat)
.option('--maxConcurrentTestRunners <n>', 'Set the number of max concurrent test runner to spawn (default: cpuCount)', parseInt)
.option('--logLevel <level>', 'Set the log level for the console. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "info"')
.option('--fileLogLevel <level>', 'Set the log4js log level for the "stryker.log" file. Possible values: fatal, error, warn, info, debug, trace, all and off. Default is "off"')
.option('--allowConsoleColors <true/false>', 'Indicates whether or not Stryker should use colors in console.', parseBoolean, true)
.parse(this.argv);
function parseBoolean(val) {
console.log('bool: ', val);
var v = val.toLocaleLowerCase();
return v !== 'false' && v !== '0';
}
LogConfigurator_1.default.configureMainProcess(program.logLevel);
var log = log4js_1.getLogger(StrykerCli.name);
// Cleanup commander state
delete program.options;
delete program.rawArgs;
delete program.args;
delete program.Command;
delete program.Option;
delete program.commands;
for (var i in program) {
if (i.charAt(0) === '_') {
delete program[i];
}
}
if (this.strykerConfig) {
program.configFile = this.strykerConfig;
}
var commands = {
init: function () { return initializer_1.initializerFactory().initialize(); },
run: function () { return new Stryker_1.default(program).runMutationTest(); }
};
if (Object.keys(commands).indexOf(this.command) >= 0) {
commands[this.command]().catch(function (err) {
log.error("an error occurred", err);
if (!log.isTraceEnabled()) {
log.info('Trouble figuring out what went wrong? Try `npx stryker run --fileLogLevel trace --logLevel debug` to get some more info.');
}
process.exitCode = 1;
process.kill(process.pid, 'SIGINT');
});
}
else {
log.error('Unknown command: "%s", supported commands: [%s], or use `stryker --help`.', this.command, Object.keys(commands));
}
};
return StrykerCli;
}());
exports.default = StrykerCli;
//# sourceMappingURL=StrykerCli.js.map
;