1- import type { Config } from "@jest/types"
1+ import { type Config } from "@jest/types"
22import tsConfig from './tsconfig.json'
3+
34const paths = tsConfig . compilerOptions . paths
45
56const aliasPattern = / ^ ( @ .* ) \/ \* $ /
@@ -8,32 +9,32 @@ const sourcePattern = /^(.*)\/\*$/
89const moduleNameMapper : { [ key : string ] : string } = { }
910
1011Object . entries ( paths ) . forEach ( ( [ alias , sourceArr ] ) => {
11- if ( ! aliasPattern . test ( alias ) ) {
12- return
13- }
14- if ( sourceArr . length !== 1 || ! sourcePattern . test ( sourceArr [ 0 ] ) ) {
15- return
16- }
17- const prefix = alias . match ( aliasPattern ) [ 1 ]
18- const pattern = `^${ prefix } /(.*)$`
19- const source = sourceArr [ 0 ] . match ( sourcePattern ) [ 1 ]
20- const sourcePath = `<rootDir>/${ source } /$1`
21- moduleNameMapper [ pattern ] = sourcePath
12+ if ( ! aliasPattern . test ( alias ) ) {
13+ return
14+ }
15+ if ( sourceArr . length !== 1 || ! sourcePattern . test ( sourceArr [ 0 ] ) ) {
16+ return
17+ }
18+ const prefix = alias . match ( aliasPattern ) [ 1 ]
19+ const pattern = `^${ prefix } /(.*)$`
20+ const source = sourceArr [ 0 ] . match ( sourcePattern ) [ 1 ]
21+ const sourcePath = `<rootDir>/${ source } /$1`
22+ moduleNameMapper [ pattern ] = sourcePath
2223} )
2324
2425console . log ( "The moduleNameMapper parsed from tsconfig.json: " )
2526console . log ( moduleNameMapper )
2627
2728const config : Config . InitialOptions = {
28- moduleNameMapper,
29- roots : [
30- "<rootDir>/test"
31- ] ,
32- testRegex : 'test/(.+)\\.test\\.(jsx?|tsx?)$' ,
33- transform : {
34- "^.+\\.tsx?$" : "ts-jest"
35- } ,
36- moduleFileExtensions : [ 'ts' , 'tsx' , 'js' , 'jsx' , 'json' , 'node' ]
29+ moduleNameMapper,
30+ roots : [
31+ "<rootDir>/test"
32+ ] ,
33+ testRegex : 'test/(.+)\\.test\\.(jsx?|tsx?)$' ,
34+ transform : {
35+ "^.+\\.tsx?$" : "ts-jest"
36+ } ,
37+ moduleFileExtensions : [ 'ts' , 'tsx' , 'js' , 'jsx' , 'json' , 'node' ]
3738}
3839
3940export default config
0 commit comments