1
- const path = require ( 'path' ) ;
2
- const { pathsToModuleNameMapper } = require ( 'ts-jest' ) ;
3
- const { compilerOptions } = require ( './tsconfig' ) ;
1
+ import path from 'node:path' ;
2
+ import url from 'node:url' ;
3
+ import { pathsToModuleNameMapper } from 'ts-jest' ;
4
+ import tsconfigJSON from './tsconfig.json' assert { type : "json " } ;
4
5
5
- const moduleNameMapper = pathsToModuleNameMapper ( compilerOptions . paths , {
6
+ const moduleNameMapper = pathsToModuleNameMapper ( tsconfigJSON . compilerOptions . paths , {
6
7
prefix : '<rootDir>/src/' ,
7
8
} ) ;
8
9
10
+ const projectPath = path . dirname ( url . fileURLToPath ( import . meta. url ) ) ;
11
+
9
12
// Global variables that are shared across the jest worker pool
10
13
// These variables must be static and serializable
11
14
const globals = {
12
15
// Absolute directory to the project root
13
- projectDir : __dirname ,
16
+ projectDir : projectPath ,
14
17
// Absolute directory to the test root
15
- testDir : path . join ( __dirname , 'tests' ) ,
18
+ testDir : path . join ( projectPath , 'tests' ) ,
16
19
// Default asynchronous test timeout
17
20
defaultTimeout : 20000 ,
18
21
// Timeouts rely on setTimeout which takes 32 bit numbers
@@ -24,7 +27,7 @@ const globals = {
24
27
// They can however receive the process environment
25
28
// Use `process.env` to set variables
26
29
27
- module . exports = {
30
+ const config = {
28
31
testEnvironment : 'node' ,
29
32
verbose : true ,
30
33
collectCoverage : false ,
@@ -40,10 +43,10 @@ module.exports = {
40
43
parser : {
41
44
syntax : "typescript" ,
42
45
tsx : true ,
43
- decorators : compilerOptions . experimentalDecorators ,
46
+ decorators : tsconfigJSON . compilerOptions . experimentalDecorators ,
44
47
dynamicImport : true ,
45
48
} ,
46
- target : compilerOptions . target . toLowerCase ( ) ,
49
+ target : tsconfigJSON . compilerOptions . target . toLowerCase ( ) ,
47
50
keepClassNames : true ,
48
51
} ,
49
52
}
@@ -77,5 +80,10 @@ module.exports = {
77
80
'jest-extended/all' ,
78
81
'<rootDir>/tests/setupAfterEnv.ts'
79
82
] ,
80
- moduleNameMapper : moduleNameMapper ,
83
+ moduleNameMapper : {
84
+ ...moduleNameMapper ,
85
+ "^(\\.{1,2}/.*)\\.js$" : "$1" ,
86
+ }
81
87
} ;
88
+
89
+ export default config ;
0 commit comments