-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesm-resolver.cjs
33 lines (31 loc) · 932 Bytes
/
esm-resolver.cjs
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
// temporary workaround while we wait for https://github.com/facebook/jest/issues/9771
const resolver = require('enhanced-resolve').create.sync({
conditionNames: ['require', 'node', 'default'],
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
})
module.exports = function (request, options) {
// This is an EXTREMELY hacky workaround for jest not being able to load manual mocks for ES Modules.
// Man, fuck this shit.
if (request.includes('data/loader'))
request = request.replace('data/loader', 'data/__mocks__/loader')
// list global module that must be resolved by defaultResolver here
if (
[
'dns/promises',
'dns',
'util',
'url',
'tls',
'http',
'https',
'stream',
'events',
'net',
'fs',
'path'
].includes(request)
) {
return options.defaultResolver(request, options)
}
return resolver(options.basedir, request)
}