UNPKG

mochapack

Version:
63 lines 2.85 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; exports.mergeMochaConfigWithConstructorOptions = exports.mergeMochaConfigWithCliOptions = void 0; var lodash_1 = require("lodash"); var config_1 = require("mocha/lib/cli/config"); var mochaOptionsFromParsedArgs_1 = require("./mochaOptionsFromParsedArgs"); var parseMochaOptsFile_1 = __importDefault(require("./parseMochaOptsFile")); /** * Don't reinvent the wheel here, use Mocha's config file loading function * under the hood */ var loadMochaConfigFile = function (configPath) { return (0, config_1.loadConfig)(configPath); }; /** * Don't reinvent the wheel here, use Mocha's config file loading function * under the hood */ var loadMochaOptsFile = function (optsFilePath) { return (0, parseMochaOptsFile_1["default"])(optsFilePath); }; /** * Merges configuration from config and/or opts file with options from CLI */ var mergeMochaConfigWithOptions = function (options, optionsOutputType, configPath, optsFilePath) { var configContents = {}; if (configPath) configContents = loadMochaConfigFile(configPath); if (optsFilePath) configContents = (0, lodash_1.defaults)(configContents, loadMochaOptsFile(optsFilePath)); if (optionsOutputType === 'cli') { return (0, lodash_1.defaults)({}, options, (0, lodash_1.pick)(configContents, mochaOptionsFromParsedArgs_1.mochaCliOptionArgs)); } return (0, lodash_1.defaults)({}, options, (0, lodash_1.omit)(configContents, mochaOptionsFromParsedArgs_1.mochaCliOptionArgs)); }; /** * If a config file is present, the options in it will be merged with those * provided in the `options`. The values in `options` are preferred over * those in the config file. * * @param options A `MochaOptions` object to extract options from * @param configPath Path to a Mocha config file */ var mergeMochaConfigWithCliOptions = function (options, configPath, optsFilePath) { return mergeMochaConfigWithOptions(options, 'cli', configPath, optsFilePath); }; exports.mergeMochaConfigWithCliOptions = mergeMochaConfigWithCliOptions; /** * If a config file is present, the options in it will be merged with those * provided in the `options`. The values in `options` are preferred over * those in the config file. * * @param options A `MochaOptions` object to extract options from * @param configPath Path to a Mocha config file */ var mergeMochaConfigWithConstructorOptions = function (options, configPath, optsFilePath) { return mergeMochaConfigWithOptions(options, 'constructor', configPath, optsFilePath); }; exports.mergeMochaConfigWithConstructorOptions = mergeMochaConfigWithConstructorOptions; //# sourceMappingURL=mergeMochaConfigWithOptions.js.map