@@ -1197,39 +1197,46 @@ test.suite('ts-node', (test) => {
11971197 expect ( stdout ) . toBe ( '' ) ;
11981198 } ) ;
11991199
1200- async function runModuleTypeTest ( project : string , ext : string ) {
1201- const { err, stderr, stdout } = await exec (
1202- `${ CMD_ESM_LOADER_WITHOUT_PROJECT } ./module-types/${ project } /test.${ ext } ` ,
1203- {
1204- env : {
1205- ...process . env ,
1206- TS_NODE_PROJECT : `./module-types/${ project } /tsconfig.json` ,
1207- } ,
1208- }
1209- ) ;
1210- expect ( err ) . toBe ( null ) ;
1211- expect ( stdout ) . toBe ( `Failures: 0\n` ) ;
1212- }
1213-
1214- test ( 'moduleTypes should allow importing CJS in an otherwise ESM project' , async ( t ) => {
1215- // A notable case where you can use ts-node's CommonJS loader, not the ESM loader, in an ESM project:
1216- // when loading a webpack.config.ts or similar config
1217- const { err, stderr, stdout } = await exec (
1218- `${ CMD_TS_NODE_WITHOUT_PROJECT_FLAG } --project ./module-types/override-to-cjs/tsconfig.json ./module-types/override-to-cjs/test-webpack-config.cjs`
1219- ) ;
1220- expect ( err ) . toBe ( null ) ;
1221- expect ( stdout ) . toBe ( `` ) ;
1222-
1223- await runModuleTypeTest ( 'override-to-cjs' , 'cjs' ) ;
1224- if ( semver . gte ( process . version , '14.13.1' ) )
1225- await runModuleTypeTest ( 'override-to-cjs' , 'mjs' ) ;
1226- } ) ;
1227-
1228- test ( 'moduleTypes should allow importing ESM in an otherwise CJS project' , async ( t ) => {
1229- await runModuleTypeTest ( 'override-to-esm' , 'cjs' ) ;
1230- // Node 14.13.0 has a bug(?) where it checks for ESM-only syntax *before* we transform the code.
1231- if ( semver . gte ( process . version , '14.13.1' ) )
1232- await runModuleTypeTest ( 'override-to-esm' , 'mjs' ) ;
1200+ test . suite ( 'moduleTypes' , ( test ) => {
1201+ suite ( 'with vanilla ts transpilation' , 'tsconfig.json' ) ;
1202+ suite ( 'with third-party-transpiler' , 'tsconfig-swc.json' ) ;
1203+ function suite ( name : string , tsconfig : string ) {
1204+ test . suite ( name , ( test ) => {
1205+ test ( 'supports CJS webpack.config.ts in an otherwise ESM project' , async ( t ) => {
1206+ // A notable case where you can use ts-node's CommonJS loader, not the ESM loader, in an ESM project:
1207+ // when loading a webpack.config.ts or similar config
1208+ const { err, stdout } = await exec (
1209+ `${ CMD_TS_NODE_WITHOUT_PROJECT_FLAG } --project ./module-types/override-to-cjs/${ tsconfig } ./module-types/override-to-cjs/test-webpack-config.cjs`
1210+ ) ;
1211+ expect ( err ) . toBe ( null ) ;
1212+ expect ( stdout ) . toBe ( `` ) ;
1213+ } ) ;
1214+ test ( 'should allow importing CJS in an otherwise ESM project' , async ( t ) => {
1215+ await run ( 'override-to-cjs' , tsconfig , 'cjs' ) ;
1216+ if ( semver . gte ( process . version , '14.13.1' ) )
1217+ await run ( 'override-to-cjs' , tsconfig , 'mjs' ) ;
1218+ } ) ;
1219+ test ( 'should allow importing ESM in an otherwise CJS project' , async ( t ) => {
1220+ await run ( 'override-to-esm' , tsconfig , 'cjs' ) ;
1221+ // Node 14.13.0 has a bug(?) where it checks for ESM-only syntax *before* we transform the code.
1222+ if ( semver . gte ( process . version , '14.13.1' ) )
1223+ await run ( 'override-to-esm' , tsconfig , 'mjs' ) ;
1224+ } ) ;
1225+ } ) ;
1226+ }
1227+ async function run ( project : string , config : string , ext : string ) {
1228+ const { err, stderr, stdout } = await exec (
1229+ `${ CMD_ESM_LOADER_WITHOUT_PROJECT } ./module-types/${ project } /test.${ ext } ` ,
1230+ {
1231+ env : {
1232+ ...process . env ,
1233+ TS_NODE_PROJECT : `./module-types/${ project } /${ config } ` ,
1234+ } ,
1235+ }
1236+ ) ;
1237+ expect ( err ) . toBe ( null ) ;
1238+ expect ( stdout ) . toBe ( `Failures: 0\n` ) ;
1239+ }
12331240 } ) ;
12341241 }
12351242
0 commit comments