forked from sheepzh/time-tracker-4-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.ts
More file actions
53 lines (45 loc) · 1.43 KB
/
jest.config.ts
File metadata and controls
53 lines (45 loc) · 1.43 KB
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
import { readFileSync } from 'fs'
import type { Config } from "jest"
import { join } from 'path'
const tsconfig = JSON.parse(readFileSync(join(process.cwd(), 'tsconfig.json'), 'utf-8'))
const { compilerOptions } = tsconfig as { compilerOptions: { paths: { [key: string]: string[] } } }
const { paths } = compilerOptions
const aliasPattern = /^(@.*)\/\*$/
const sourcePattern = /^(.*)\/\*$/
const moduleNameMapper: { [key: string]: string } = {}
Object.entries(paths).forEach(([alias, sourceArr]) => {
const aliasMatch = alias.match(aliasPattern)
if (!aliasMatch) {
return
}
if (!Array.isArray(sourceArr) || 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 = {
moduleNameMapper,
roots: [
"<rootDir>/test",
"<rootDir>/test-e2e",
],
testRegex: '(.+)\\.test\\.(jsx?|tsx?)$',
transform: {
"^.+\\.tsx?$": "@swc/jest"
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
setupFiles: [
'<rootDir>/test/jest.setup.ts',
],
}
export default config