-
Notifications
You must be signed in to change notification settings - Fork 124
/
jest-resolver.js
48 lines (44 loc) · 1.37 KB
/
jest-resolver.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
const resolve = require('enhanced-resolve');
// const resolve2 = require('resolve');
/**
* This custom jest resolver makes sure symlinks are not followed, so preserveSymlinks=true.
* Especially in framework-integration test break if symlinks are followed.
*
* NODE_PRESERVE_SYMLINKS=1 npm run test packages/framework-integration/tests/
* and other alternatives do not work anymore, hence the need for this custom resolver.
*/
/**
* @typedef {{
basedir: string;
browser?: boolean;
defaultResolver: (request: string, options: ResolverOptions) => string;
extensions?: readonly string[];
moduleDirectory?: readonly string[];
paths?: readonly string[];
rootDir?: string;
}} ResolverOptions
*/
/**
* @param {string} request
* @param {ResolverOptions} options
*/
const myResolve = resolve.create.sync({
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.node'],
symlinks: false,
conditionNames: ['require', 'node', 'default'],
});
module.exports = (request, options) => {
try {
const res = myResolve(options.basedir, request);
// const res = resolve2.sync(request, {
// ...options,
// preserveSymlinks: true,
// });
return res;
} catch (e) {
if (e.code === 'MODULE_NOT_FOUND') {
return options.defaultResolver(request, options);
}
throw e;
}
};