UNPKG

1.97 kBJavaScriptView Raw
1import { URL } from 'url';
2import fs from 'fs';
3const mochaSchema = JSON.parse(fs.readFileSync(new URL('../schema/mocha-runner-options.json', import.meta.url), 'utf-8'));
4export function serializeMochaLoadOptionsArguments(mochaOptions) {
5 const args = [];
6 if (mochaOptions['no-config']) {
7 args.push('--no-config');
8 }
9 if (mochaOptions['no-opts']) {
10 args.push('--no-opts');
11 }
12 if (mochaOptions['no-package']) {
13 args.push('--no-package');
14 }
15 if (mochaOptions.package) {
16 args.push('--package');
17 args.push(mochaOptions.package);
18 }
19 if (mochaOptions.opts) {
20 args.push('--opts');
21 args.push(mochaOptions.opts);
22 }
23 if (mochaOptions.config) {
24 args.push('--config');
25 args.push(mochaOptions.config);
26 }
27 return args;
28}
29const SUPPORTED_MOCHA_OPTIONS = Object.freeze(Object.keys(mochaSchema.properties.mochaOptions.properties));
30/**
31 * Filter out those config values that are actually useful to run mocha with Stryker
32 * @param rawConfig The raw parsed mocha configuration
33 */
34export function filterConfig(rawConfig) {
35 var _a;
36 const options = {};
37 Object.keys(rawConfig)
38 .filter((rawOption) => SUPPORTED_MOCHA_OPTIONS.some((supportedOption) => rawOption === supportedOption))
39 .forEach((option) => (options[option] = rawConfig[option]));
40 // Config file can also contain positional arguments. They are provided under the `_` key
41 // For example:
42 // When mocha.opts contains "--async-only test/**/*.js", then "test/**/*.js will be the positional argument
43 // We must provide it to mocha as "spec"
44 if ((_a = rawConfig._) === null || _a === void 0 ? void 0 : _a.length) {
45 if (!options.spec) {
46 options.spec = [];
47 }
48 const specs = options.spec;
49 rawConfig._.forEach((positionalArgument) => specs.push(positionalArgument));
50 }
51 return options;
52}
53//# sourceMappingURL=utils.js.map
\No newline at end of file