Skip to content

Commit adf7945

Browse files
committed
Fix Jest tests
1 parent 9730bfb commit adf7945

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

jest.config.base.js

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,36 @@
11
import { createJsWithTsPreset } from 'ts-jest';
22

3+
const tsconfig = {
4+
// Relative imports in our TS code include `.ts` extensions.
5+
// When compiling the package, TS rewrites them to `.js`,
6+
// but ts-jest runs on the original code where the `.js` files don't exist,
7+
// so this setting needs to be disabled here.
8+
rewriteRelativeImportExtensions: false,
9+
// Override hybrid module kind (Node16/NodeNext) to avoid ts-jest warning
10+
// about requiring isolatedModules: true
11+
module: 'ESNext',
12+
};
13+
14+
const tsJestPreset = createJsWithTsPreset({
15+
tsconfig,
16+
});
17+
318
// Global Jest configuration for the monorepo
419
// Contains common settings that all packages inherit
520
export default {
621
// === 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-
}),
22+
// ts-jest preset with custom TypeScript settings, extended to handle .cts/.mts files
23+
...tsJestPreset,
24+
transform: {
25+
...tsJestPreset.transform,
26+
// Extend transform to include CommonJS TypeScript (.cts) and ES Module TypeScript (.mts) files
27+
'^.+\\.[cm]?ts$': [
28+
'ts-jest',
29+
{
30+
tsconfig,
31+
},
32+
],
33+
},
1734

1835
// === Test Environment Configuration ===
1936
testEnvironment: 'jsdom',
@@ -23,5 +40,6 @@ export default {
2340
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
2441

2542
// === Common Module File Extensions ===
26-
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'json'],
43+
// Include cts/mts for CommonJS/ES module TypeScript files
44+
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx', 'cts', 'mts', 'json'],
2745
};

0 commit comments

Comments
 (0)