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 tsconfigJSON from './tsconfig.json' assert { type : " json " } ;
44
5- const moduleNameMapper = pathsToModuleNameMapper ( compilerOptions . paths , {
6- prefix : '<rootDir>/src/' ,
7- } ) ;
5+ const projectPath = path . dirname ( url . fileURLToPath ( import . meta. url ) ) ;
86
97// Global variables that are shared across the jest worker pool
108// These variables must be static and serializable
119const globals = {
1210 // Absolute directory to the project root
13- projectDir : __dirname ,
11+ projectDir : projectPath ,
1412 // Absolute directory to the test root
15- testDir : path . join ( __dirname , 'tests' ) ,
13+ testDir : path . join ( projectPath , 'tests' ) ,
1614 // Default asynchronous test timeout
1715 defaultTimeout : 20000 ,
1816 // Timeouts rely on setTimeout which takes 32 bit numbers
@@ -24,7 +22,7 @@ const globals = {
2422// They can however receive the process environment
2523// Use `process.env` to set variables
2624
27- module . exports = {
25+ const config = {
2826 testEnvironment : 'node' ,
2927 verbose : true ,
3028 collectCoverage : false ,
@@ -40,10 +38,10 @@ module.exports = {
4038 parser : {
4139 syntax : "typescript" ,
4240 tsx : true ,
43- decorators : compilerOptions . experimentalDecorators ,
41+ decorators : tsconfigJSON . compilerOptions . experimentalDecorators ,
4442 dynamicImport : true ,
4543 } ,
46- target : compilerOptions . target . toLowerCase ( ) ,
44+ target : tsconfigJSON . compilerOptions . target . toLowerCase ( ) ,
4745 keepClassNames : true ,
4846 } ,
4947 }
@@ -77,5 +75,10 @@ module.exports = {
7775 'jest-extended/all' ,
7876 '<rootDir>/tests/setupAfterEnv.ts'
7977 ] ,
80- moduleNameMapper : moduleNameMapper ,
78+ moduleNameMapper : {
79+ "^(\\.{1,2}/.*)\\.js$" : "$1" ,
80+ } ,
81+ extensionsToTreatAsEsm : [ '.ts' , '.tsx' , '.mts' ] ,
8182} ;
83+
84+ export default config ;
0 commit comments