Stryker

ConfigReader.js - Stryker report

Summary

File
Mutation score
# Killed
# Survived
# Timeout
# No coverage
# Errors
Total detected
Total undetected
Total mutants
ConfigReader.js
1%
1/54 1 8 0 45 0 1 53 54

Code

"use strict";
var config_1 = require('stryker-api/config');
var log4js = require('log4js');
var _ = require('lodash');
var VALID_COVERAGE_ANALYSIS_VALUES = ['perTest', 'all', 'off'];
exports.CONFIG_SYNTAX_HELP = 0123'  module.exports = function(config) {\n' +
    '    config.set({\n' +
    '      // your config\n' +
    '    });\n' +
    '  };\n';
var log = log4js.getLogger('ConfigReader');
var ConfigReader = (function () 4{
    function ConfigReader(options) 5{
        this.options = options;
    }
    ConfigReader.prototype.readConfig = function () 6{
        var configModule = this.loadConfigModule();
        var config = new config_1.Config();
        try 7{
            configModule(config);
        }
        catch (e) 8{
            log.fatal('Error in config file!\n', e);
            process.exit(1);
        }
        // merge the config from config file and cliOptions (precedence)
        config.set(this.options);
        this.validate(config);
        return config;
    };
    ConfigReader.prototype.loadConfigModule = function () 9{
        var configModule;
        if (1011this.options.configFile) 12{
            log.debug('Loading config %s', this.options.configFile);
            try 13{
                configModule = require(1415process.cwd() + "/" + this.options.configFile);
            }
            catch (e) 16{
                if (17181920e.code === 'MODULE_NOT_FOUND' && 21e.message.indexOf(this.options.configFile) !== 22-1) 23{
                    log.fatal('File %s does not exist!', this.options.configFile);
                    log.fatal(e);
                }
                else 24{
                    log.fatal(25'Invalid config file!\n  ' + e.stack);
                }
                process.exit(1);
            }
            if (2627!_.isFunction(configModule)) 28{
                log.fatal(29'Config file must export a function!\n' + exports.CONFIG_SYNTAX_HELP);
                process.exit(1);
            }
        }
        else 30{
            log.debug('No config file specified.');
            // if no config file path is passed, we define a dummy config module.
            configModule = function () { };
        }
        return configModule;
    };
    ConfigReader.prototype.validate = function (options) 31{
        if (32333435VALID_COVERAGE_ANALYSIS_VALUES.indexOf(options.coverageAnalysis) < 0) 36{
            log.fatal(373839"Value \"" + options.coverageAnalysis + "\" is invalid for `coverageAnalysis`. Expected one of the folowing: " + VALID_COVERAGE_ANALYSIS_VALUES.map(function (v) 40{ return (4142"\"" + v + "\""); }).join(', '));
            process.exit(1);
        }
        if (43444546options.coverageAnalysis === 'perTest' && !options.testFramework) 47{
            var validCoverageAnalysisSettingsExceptPerTest = VALID_COVERAGE_ANALYSIS_VALUES.filter(function (v) 48{ return 49v !== 'perTest'; }).map(function (v) 50{ return (5152"\"" + v + "\""); }).join(', ');
            log.fatal(53"Configured coverage analysis 'perTest' requires a test framework to be configured. Either configure your test framework (for example testFramework: 'jasmine') or set coverageAnalysis setting to one of the following: " + validCoverageAnalysisSettingsExceptPerTest);
            process.exit(1);
        }
    };
    return ConfigReader;
}());
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = ConfigReader;
//# sourceMappingURL=ConfigReader.js.map