UNPKG

@stryker-mutator/mocha-runner

Version:

A plugin to use the mocha test runner in Stryker, the JavaScript mutation testing framework

53 lines 1.97 kB
import { URL } from 'url'; import fs from 'fs'; const mochaSchema = JSON.parse(fs.readFileSync(new URL('../schema/mocha-runner-options.json', import.meta.url), 'utf-8')); export function serializeMochaLoadOptionsArguments(mochaOptions) { const args = []; if (mochaOptions['no-config']) { args.push('--no-config'); } if (mochaOptions['no-opts']) { args.push('--no-opts'); } if (mochaOptions['no-package']) { args.push('--no-package'); } if (mochaOptions.package) { args.push('--package'); args.push(mochaOptions.package); } if (mochaOptions.opts) { args.push('--opts'); args.push(mochaOptions.opts); } if (mochaOptions.config) { args.push('--config'); args.push(mochaOptions.config); } return args; } const SUPPORTED_MOCHA_OPTIONS = Object.freeze(Object.keys(mochaSchema.properties.mochaOptions.properties)); /** * Filter out those config values that are actually useful to run mocha with Stryker * @param rawConfig The raw parsed mocha configuration */ export function filterConfig(rawConfig) { var _a; const options = {}; Object.keys(rawConfig) .filter((rawOption) => SUPPORTED_MOCHA_OPTIONS.some((supportedOption) => rawOption === supportedOption)) .forEach((option) => (options[option] = rawConfig[option])); // Config file can also contain positional arguments. They are provided under the `_` key // For example: // When mocha.opts contains "--async-only test/**/*.js", then "test/**/*.js will be the positional argument // We must provide it to mocha as "spec" if ((_a = rawConfig._) === null || _a === void 0 ? void 0 : _a.length) { if (!options.spec) { options.spec = []; } const specs = options.spec; rawConfig._.forEach((positionalArgument) => specs.push(positionalArgument)); } return options; } //# sourceMappingURL=utils.js.map