-
Notifications
You must be signed in to change notification settings - Fork 19
/
jest.config.js
116 lines (93 loc) · 1.74 KB
/
jest.config.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// @ts-check
const { basename, extname, dirname } = require('path');
/**
* // @type { import('@jest/types').Config.InitialOptions }
* @type { import('ts-jest').InitialOptionsTsJest }
*/
let jestConfig = {
}
/**
* @param {string} name
* @returns {string}
* @private
*/
function _requireResolve(name)
{
let result;
try
{
// @ts-ignore
const { requireResolveExtra, requireResolveCore } = require('@yarn-tool/require-resolve');
const paths = [
requireResolveExtra('@bluelovers/tsdx').result,
requireResolveExtra('tsdx').result,
].filter(Boolean);
result = requireResolveCore(name, {
includeGlobal: true,
includeCurrentDirectory: true,
paths,
})
}
catch (e)
{
}
result = result || require.resolve(name);
console.info('[require.resolve]', name, '=>', result)
return result
}
let _ok = true;
try
{
if (!jestConfig.preset)
{
let result = require('@yarn-tool/ws-find-up-paths').findUpPathsWorkspaces([
'jest-preset.js',
'jest.config.js',
], {
ignoreCurrentPackage: true,
onlyFiles: true,
}).result;
if (result)
{
let name = basename(result, extname(result))
switch (name)
{
case 'jest-preset':
jestConfig.preset = dirname(result);
break;
default:
jestConfig = {
...require(result),
jestConfig,
};
break;
}
_ok = false;
}
}
}
catch (e)
{
}
try
{
if (_ok && !jestConfig.preset)
{
let result = _requireResolve('@bluelovers/jest-config/package.json');
if (result)
{
jestConfig.preset = dirname(result);
_ok = false;
}
}
}
catch (e)
{
}
if (_ok && !jestConfig.preset)
{
jestConfig.preset = '@bluelovers/jest-config';
_ok = false;
}
console.info(`jest.config.preset: ${jestConfig.preset}`);
module.exports = jestConfig