@@ -9,6 +9,7 @@ import { unlinkSync, existsSync, lstatSync } from 'fs'
99import * as promisify from 'util.promisify'
1010import { sync as rimrafSync } from 'rimraf'
1111import { createRequire , createRequireFromPath } from 'module'
12+ import { pathToFileURL } from 'url'
1213import Module = require( 'module' )
1314
1415const execP = promisify ( exec )
@@ -28,7 +29,7 @@ let { register, create, VERSION }: typeof tsNodeTypes = {} as any
2829
2930// Pack and install ts-node locally, necessary to test package "exports"
3031before ( async function ( ) {
31- this . timeout ( 30000 )
32+ this . timeout ( 5 * 60e3 )
3233 rimrafSync ( join ( TEST_DIR , 'node_modules' ) )
3334 await execP ( `npm install` , { cwd : TEST_DIR } )
3435 const packageLockPath = join ( TEST_DIR , 'package-lock.json' )
@@ -344,10 +345,15 @@ describe('ts-node', function () {
344345 } )
345346 } )
346347
347- it . skip ( 'should use source maps with react tsx' , function ( done ) {
348- exec ( `${ cmd } -r ./tests/emit-compiled.ts tests/jsx-react.tsx` , function ( err , stdout ) {
349- expect ( err ) . to . equal ( null )
350- expect ( stdout ) . to . equal ( 'todo' )
348+ it ( 'should use source maps with react tsx' , function ( done ) {
349+ exec ( `${ cmd } tests/throw-react-tsx.tsx` , function ( err , stdout ) {
350+ expect ( err ) . not . to . equal ( null )
351+ expect ( err ! . message ) . to . contain ( [
352+ `${ join ( __dirname , '../tests/throw-react-tsx.tsx' ) } :100` ,
353+ ' bar () { throw new Error(\'this is a demo\') }' ,
354+ ' ^' ,
355+ 'Error: this is a demo'
356+ ] . join ( '\n' ) )
351357
352358 return done ( )
353359 } )
@@ -471,7 +477,7 @@ describe('ts-node', function () {
471477 const BIN_EXEC = `"${ BIN_PATH } " --project tests/tsconfig-options/tsconfig.json`
472478
473479 it ( 'should override compiler options from env' , function ( done ) {
474- exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options .js` , {
480+ exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options1 .js` , {
475481 env : {
476482 ...process . env ,
477483 TS_NODE_COMPILER_OPTIONS : '{"typeRoots": ["env-typeroots"]}'
@@ -485,33 +491,38 @@ describe('ts-node', function () {
485491 } )
486492
487493 it ( 'should use options from `tsconfig.json`' , function ( done ) {
488- exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options .js` , function ( err , stdout ) {
494+ exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options1 .js` , function ( err , stdout ) {
489495 expect ( err ) . to . equal ( null )
490496 const { options, config } = JSON . parse ( stdout )
491497 expect ( config . options . typeRoots ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/tsconfig-typeroots' ) . replace ( / \\ / g, '/' ) ] )
492498 expect ( config . options . types ) . to . deep . equal ( [ 'tsconfig-tsnode-types' ] )
493499 expect ( options . pretty ) . to . equal ( undefined )
494500 expect ( options . skipIgnore ) . to . equal ( false )
495501 expect ( options . transpileOnly ) . to . equal ( true )
502+ expect ( options . require ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/required1.js' ) ] )
496503 return done ( )
497504 } )
498505 } )
499506
500- it ( 'should have flags override `tsconfig.json`' , function ( done ) {
501- exec ( `${ BIN_EXEC } --skip-ignore --compiler-options "{\\"types\\":[\\"flags-types\\"]}" tests/tsconfig-options/log -options.js` , function ( err , stdout ) {
507+ it ( 'should have flags override / merge with `tsconfig.json`' , function ( done ) {
508+ exec ( `${ BIN_EXEC } --skip-ignore --compiler-options "{\\"types\\":[\\"flags-types\\"]}" --require ./ tests/tsconfig-options/required2.js tests/tsconfig -options/log-options2 .js` , function ( err , stdout ) {
502509 expect ( err ) . to . equal ( null )
503510 const { options, config } = JSON . parse ( stdout )
504511 expect ( config . options . typeRoots ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/tsconfig-typeroots' ) . replace ( / \\ / g, '/' ) ] )
505512 expect ( config . options . types ) . to . deep . equal ( [ 'flags-types' ] )
506513 expect ( options . pretty ) . to . equal ( undefined )
507514 expect ( options . skipIgnore ) . to . equal ( true )
508515 expect ( options . transpileOnly ) . to . equal ( true )
516+ expect ( options . require ) . to . deep . equal ( [
517+ join ( __dirname , '../tests/tsconfig-options/required1.js' ) ,
518+ './tests/tsconfig-options/required2.js'
519+ ] )
509520 return done ( )
510521 } )
511522 } )
512523
513524 it ( 'should have `tsconfig.json` override environment' , function ( done ) {
514- exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options .js` , {
525+ exec ( `${ BIN_EXEC } tests/tsconfig-options/log-options1 .js` , {
515526 env : {
516527 ...process . env ,
517528 TS_NODE_PRETTY : 'true' ,
@@ -525,6 +536,7 @@ describe('ts-node', function () {
525536 expect ( options . pretty ) . to . equal ( true )
526537 expect ( options . skipIgnore ) . to . equal ( false )
527538 expect ( options . transpileOnly ) . to . equal ( true )
539+ expect ( options . require ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/required1.js' ) ] )
528540 return done ( )
529541 } )
530542 } )
@@ -724,7 +736,7 @@ describe('ts-node', function () {
724736 describe ( 'esm' , ( ) => {
725737 this . slow ( 1000 )
726738
727- const cmd = `node --loader ts-node/esm.mjs `
739+ const cmd = `node --loader ts-node/esm`
728740
729741 if ( semver . gte ( process . version , '13.0.0' ) ) {
730742 it ( 'should compile and execute as ESM' , ( done ) => {
@@ -735,6 +747,27 @@ describe('ts-node', function () {
735747 return done ( )
736748 } )
737749 } )
750+ it ( 'should use source maps' , function ( done ) {
751+ exec ( `${ cmd } throw.ts` , { cwd : join ( __dirname , '../tests/esm' ) } , function ( err , stdout ) {
752+ expect ( err ) . not . to . equal ( null )
753+ expect ( err ! . message ) . to . contain ( [
754+ `${ pathToFileURL ( join ( __dirname , '../tests/esm/throw.ts' ) ) } :100` ,
755+ ' bar () { throw new Error(\'this is a demo\') }' ,
756+ ' ^' ,
757+ 'Error: this is a demo'
758+ ] . join ( '\n' ) )
759+
760+ return done ( )
761+ } )
762+ } )
763+ it ( 'supports --experimental-specifier-resolution=node' , ( done ) => {
764+ exec ( `${ cmd } --experimental-specifier-resolution=node index.ts` , { cwd : join ( __dirname , '../tests/esm-node-resolver' ) } , function ( err , stdout ) {
765+ expect ( err ) . to . equal ( null )
766+ expect ( stdout ) . to . equal ( 'foo bar baz biff\n' )
767+
768+ return done ( )
769+ } )
770+ } )
738771
739772 describe ( 'supports experimental-specifier-resolution=node' , ( ) => {
740773 it ( 'via --experimental-specifier-resolution' , ( done ) => {
0 commit comments