11import { createJsWithTsPreset } from 'ts-jest' ;
22
3+ const tsconfig = {
4+ // Otherwise we get warnings in tests
5+ esModuleInterop : true ,
6+ // Relative imports in our TS code include `.ts` extensions.
7+ // When compiling the package, TS rewrites them to `.js`,
8+ // but ts-jest runs on the original code where the `.js` files don't exist,
9+ // so this setting needs to be disabled here.
10+ rewriteRelativeImportExtensions : false ,
11+ // Override hybrid module kind (Node16/NodeNext) to avoid ts-jest warning
12+ // about requiring isolatedModules: true
13+ module : 'ESNext' ,
14+ } ;
15+
16+ const tsJestPreset = createJsWithTsPreset ( {
17+ tsconfig,
18+ } ) ;
19+
320// Global Jest configuration for the monorepo
421// Contains common settings that all packages inherit
522export default {
623 // === TypeScript Configuration ===
7- // ts-jest preset with custom TypeScript settings
8- ...createJsWithTsPreset ( {
9- tsconfig : {
10- // Relative imports in our TS code include `.ts` extensions.
11- // When compiling the package, TS rewrites them to `.js`,
12- // but ts-jest runs on the original code where the `.js` files don't exist,
13- // so this setting needs to be disabled here.
14- rewriteRelativeImportExtensions : false ,
15- } ,
16- } ) ,
24+ // ts-jest preset with custom TypeScript settings, extended to handle .cts/.mts files
25+ ...tsJestPreset ,
26+ transform : {
27+ ...tsJestPreset . transform ,
28+ // Extend transform to include CommonJS TypeScript (.cts) and ES Module TypeScript (.mts) files
29+ '^.+\\.[cm]?ts$' : [
30+ 'ts-jest' ,
31+ {
32+ tsconfig,
33+ } ,
34+ ] ,
35+ } ,
1736
1837 // === Test Environment Configuration ===
1938 testEnvironment : 'jsdom' ,
@@ -23,5 +42,6 @@ export default {
2342 testMatch : [ '**/?(*.)+(spec|test).[jt]s?(x)' ] ,
2443
2544 // === Common Module File Extensions ===
26- moduleFileExtensions : [ 'js' , 'jsx' , 'ts' , 'tsx' , 'json' ] ,
45+ // Include cts/mts for CommonJS/ES module TypeScript files
46+ moduleFileExtensions : [ 'js' , 'jsx' , 'ts' , 'tsx' , 'cts' , 'mts' , 'json' ] ,
2747} ;
0 commit comments