@@ -6,7 +6,7 @@ import { commonJS, itGte, itLt, USE_ESM } from "$repo-utils";
66const { __dirname, require } = commonJS ( import . meta. url ) ;
77
88// We skip older versions of node testing for two reasons.
9- // 1. ts-node and ts don't support the old version of node.
9+ // 1. ts don't support the old version of node.
1010// 2. In the old version of node, jest has been registered in `require.extensions`, which will cause babel to disable the transforming as expected.
1111const shouldSkip = semver . lt ( process . version , "14.0.0" ) ;
1212
@@ -77,7 +77,7 @@ const nodeLt23_6_andRequireBabelPackages =
7777 // This isn't by design, but reflects the status quo when running in Node.js
7878 // versions that don't have native support for .ts files.
7979 // It can be changed if needed.
80- nodeLt23_6 ( "show not support .ts config file" , ( ) => {
80+ nodeLt23_6 ( "should not support .ts config file" , ( ) => {
8181 expect ( ( ) => {
8282 loadPartialConfigSync ( {
8383 configFile : path . join (
@@ -90,40 +90,28 @@ const nodeLt23_6_andRequireBabelPackages =
9090 ) ;
9191 } ) ;
9292
93- it ( "should work with ts-node" , async ( ) => {
94- const service = require ( "ts-node" ) . register ( {
95- experimentalResolver : true ,
96- compilerOptions : {
97- module : "CommonJS" ,
98- } ,
99- } ) ;
100- service . enabled ( true ) ;
101-
102- try {
103- require (
104- path . join (
105- __dirname ,
106- "fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts" ,
107- ) ,
108- ) ;
109-
110- const config = loadPartialConfigSync ( {
111- configFile : path . join (
112- __dirname ,
113- "fixtures/config-ts/simple-cts-with-ts-node/babel.config.cts" ,
114- ) ,
93+ nodeLt23_6 ( "should search .ts config file and throw" , ( ) => {
94+ expect ( ( ) => {
95+ loadPartialConfigSync ( {
96+ root : path . join ( __dirname , "fixtures/config-ts/simple-ts-cjs" ) ,
11597 } ) ;
98+ } ) . toThrow (
99+ / Y o u a r e u s i n g a .t s c o n f i g f i l e , b u t B a b e l o n l y s u p p o r t s t r a n s p i l i n g .c t s c o n f i g s / ,
100+ ) ;
101+ } ) ;
116102
117- expect ( config . options . targets ) . toMatchInlineSnapshot ( `
103+ nodeGte23_6 ( "should search for .cts config files" , ( ) => {
104+ const config = loadPartialConfigSync ( {
105+ root : path . join ( __dirname , "fixtures/config-ts/simple-cts-no-modules" ) ,
106+ } ) ;
107+
108+ expect ( config . options . targets ) . toMatchInlineSnapshot ( `
118109 Object {
119110 "node": "12.0.0",
120111 }
121112 ` ) ;
122113
123- expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
124- } finally {
125- service . enabled ( false ) ;
126- }
114+ expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
127115 } ) ;
128116
129117 nodeGte23_6 ( "should support .cts when available natively" , ( ) => {
@@ -154,6 +142,20 @@ const nodeLt23_6_andRequireBabelPackages =
154142 } ) . toThrow ( / i m p o r t e q u a l s d e c l a r a t i o n i s n o t s u p p o r t e d i n s t r i p - o n l y m o d e / ) ;
155143 } ) ;
156144
145+ nodeGte23_6 ( "should search for .ts config files" , ( ) => {
146+ const config = loadPartialConfigSync ( {
147+ root : path . join ( __dirname , "fixtures/config-ts/simple-ts-cjs" ) ,
148+ } ) ;
149+
150+ expect ( config . options . targets ) . toMatchInlineSnapshot ( `
151+ Object {
152+ "node": "12.0.0",
153+ }
154+ ` ) ;
155+
156+ expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
157+ } ) ;
158+
157159 nodeGte23_6 (
158160 "should use native TS support for .ts (cjs) when available" ,
159161 ( ) => {
@@ -193,4 +195,45 @@ const nodeLt23_6_andRequireBabelPackages =
193195 expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
194196 } ,
195197 ) ;
198+
199+ nodeLt23_6 ( "should search .mts config file and throw" , ( ) => {
200+ expect ( ( ) => {
201+ loadPartialConfigSync ( {
202+ root : path . join ( __dirname , "fixtures/config-ts/simple-mts-modules" ) ,
203+ } ) ;
204+ } ) . toThrow (
205+ / Y o u a r e u s i n g a .m t s c o n f i g f i l e , b u t B a b e l o n l y s u p p o r t s t r a n s p i l i n g .c t s c o n f i g s / ,
206+ ) ;
207+ } ) ;
208+
209+ nodeGte23_6 ( "should use native TS support for .mts when available" , ( ) => {
210+ const config = loadPartialConfigSync ( {
211+ configFile : path . join (
212+ __dirname ,
213+ "fixtures/config-ts/simple-mts-modules/babel.config.mts" ,
214+ ) ,
215+ } ) ;
216+
217+ expect ( config . options . targets ) . toMatchInlineSnapshot ( `
218+ Object {
219+ "node": "12.0.0",
220+ }
221+ ` ) ;
222+
223+ expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
224+ } ) ;
225+
226+ nodeGte23_6 ( "should search for .mts config files" , ( ) => {
227+ const config = loadPartialConfigSync ( {
228+ root : path . join ( __dirname , "fixtures/config-ts/simple-mts-modules" ) ,
229+ } ) ;
230+
231+ expect ( config . options . targets ) . toMatchInlineSnapshot ( `
232+ Object {
233+ "node": "12.0.0",
234+ }
235+ ` ) ;
236+
237+ expect ( config . options . sourceRoot ) . toMatchInlineSnapshot ( `"/a/b"` ) ;
238+ } ) ;
196239} ) ;
0 commit comments