-
Notifications
You must be signed in to change notification settings - Fork 17
/
jest.config.ts
39 lines (33 loc) · 1.03 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
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]) => {
if (!aliasPattern.test(alias)) {
return
}
if (sourceArr.length !== 1 || !sourcePattern.test(sourceArr[0])) {
return
}
const prefix = alias.match(aliasPattern)[1]
const pattern = `^${prefix}/(.*)$`
const source = sourceArr[0].match(sourcePattern)[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"
],
testRegex: 'test/(.+)\\.test\\.(jsx?|tsx?)$',
transform: {
"^.+\\.tsx?$": "ts-jest"
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node']
}
export default config