1 | import { URL } from 'url';
|
2 | import fs from 'fs';
|
3 | const mochaSchema = JSON.parse(fs.readFileSync(new URL('../schema/mocha-runner-options.json', import.meta.url), 'utf-8'));
|
4 | export 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 | }
|
29 | const SUPPORTED_MOCHA_OPTIONS = Object.freeze(Object.keys(mochaSchema.properties.mochaOptions.properties));
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | export 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 |
|
41 |
|
42 |
|
43 |
|
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 |
|
\ | No newline at end of file |