@@ -25,6 +25,37 @@ describe('readConfigFileAndSetRootDir', () => {
2525
2626 expect ( config ) . toEqual ( { notify : true , rootDir} ) ;
2727 } ) ;
28+
29+ test ( 'throws a clear error when native import fails, without falling back to ts-node' , async ( ) => {
30+ jest
31+ . mocked ( requireOrImportModule )
32+ . mockRejectedValueOnce ( new Error ( 'Unknown file extension ".mts"' ) ) ;
33+
34+ const configPath = path . join (
35+ path . resolve ( 'some' , 'path' , 'to' ) ,
36+ 'jest.config.mts' ,
37+ ) ;
38+ await expect ( readConfigFileAndSetRootDir ( configPath ) ) . rejects . toThrow (
39+ / j e s t \. c o n f i g \. m t s r e q u i r e s n a t i v e T y p e S c r i p t s u p p o r t / ,
40+ ) ;
41+ // loadTSConfigFile reads the file for docblock parsing — it must not be called
42+ expect ( fs . readFileSync ) . not . toHaveBeenCalled ( ) ;
43+ } ) ;
44+
45+ test ( 'throws a clear error when native import fails with a SyntaxError' , async ( ) => {
46+ jest
47+ . mocked ( requireOrImportModule )
48+ . mockRejectedValueOnce ( new SyntaxError ( 'Unexpected token' ) ) ;
49+
50+ const configPath = path . join (
51+ path . resolve ( 'some' , 'path' , 'to' ) ,
52+ 'jest.config.mts' ,
53+ ) ;
54+ await expect ( readConfigFileAndSetRootDir ( configPath ) ) . rejects . toThrow (
55+ / j e s t \. c o n f i g \. m t s r e q u i r e s n a t i v e T y p e S c r i p t s u p p o r t / ,
56+ ) ;
57+ expect ( fs . readFileSync ) . not . toHaveBeenCalled ( ) ;
58+ } ) ;
2859 } ) ;
2960
3061 describe ( 'JavaScript file' , ( ) => {
0 commit comments