-
Notifications
You must be signed in to change notification settings - Fork 12
/
getMochaOptions.js
37 lines (27 loc) · 923 Bytes
/
getMochaOptions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const path = require('path');
const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('jest-runner-mocha', { sync: true });
const normalize = (jestConfig, { cliOptions: rawCliOptions = {} }) => {
const cliOptions = Object.assign({}, rawCliOptions);
if (cliOptions.compiler && !path.isAbsolute(cliOptions.compiler)) {
cliOptions.compiler = path.resolve(jestConfig.rootDir, cliOptions.compiler);
}
if (cliOptions.file) {
const file = [].concat(cliOptions.file);
cliOptions.file = file.map(f => {
if (path.isAbsolute(f)) {
return f;
}
return path.resolve(jestConfig.rootDir, f);
});
}
return { cliOptions };
};
const getMochaOptions = jestConfig => {
const result = explorer.load(jestConfig.rootDir);
if (result) {
return normalize(jestConfig, result.config);
}
return normalize(jestConfig, {});
};
module.exports = getMochaOptions;