-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathjest.config.ts
46 lines (39 loc) · 1.16 KB
/
jest.config.ts
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
import { type Config } from "@jest/types"
import tsConfig from './tsconfig.json'
const paths = tsConfig.compilerOptions.paths
const aliasPattern = /^(@.*)\/\*$/
const sourcePattern = /^(.*)\/\*$/
const moduleNameMapper: { [key: string]: string } = {}
Object.entries(paths).forEach(([alias, sourceArr]) => {
const aliasMatch = alias.match(aliasPattern)
if (!aliasMatch) {
return
}
if (sourceArr.length !== 1) {
return
}
const sourceMath = sourceArr[0]?.match(sourcePattern)
if (!sourceMath) {
return
}
const prefix = aliasMatch[1]
const pattern = `^${prefix}/(.*)$`
const source = sourceMath[1]
const sourcePath = `<rootDir>/${source}/$1`
moduleNameMapper[pattern] = sourcePath
})
console.log("The moduleNameMapper parsed from tsconfig.json: ")
console.log(moduleNameMapper)
const config: Config.InitialOptions = {
moduleNameMapper,
roots: [
"<rootDir>/test",
"<rootDir>/test-e2e",
],
testRegex: '(.+)\\.test\\.(jsx?|tsx?)$',
transform: {
"^.+\\.tsx?$": "@swc/jest"
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
}
export default config