@@ -9,6 +9,7 @@ import { unlinkSync, existsSync, lstatSync } from 'fs'
9
9
import * as promisify from 'util.promisify'
10
10
import { sync as rimrafSync } from 'rimraf'
11
11
import { createRequire , createRequireFromPath } from 'module'
12
+ import { pathToFileURL } from 'url'
12
13
import Module = require( 'module' )
13
14
14
15
const execP = promisify ( exec )
@@ -28,7 +29,7 @@ let { register, create, VERSION }: typeof tsNodeTypes = {} as any
28
29
29
30
// Pack and install ts-node locally, necessary to test package "exports"
30
31
before ( async function ( ) {
31
- this . timeout ( 30000 )
32
+ this . timeout ( 5 * 60e3 )
32
33
rimrafSync ( join ( TEST_DIR , 'node_modules' ) )
33
34
await execP ( `npm install` , { cwd : TEST_DIR } )
34
35
const packageLockPath = join ( TEST_DIR , 'package-lock.json' )
@@ -344,10 +345,15 @@ describe('ts-node', function () {
344
345
} )
345
346
} )
346
347
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' ) )
351
357
352
358
return done ( )
353
359
} )
@@ -471,7 +477,7 @@ describe('ts-node', function () {
471
477
const BIN_EXEC = `"${ BIN_PATH } " --project tests/tsconfig-options/tsconfig.json`
472
478
473
479
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` , {
475
481
env : {
476
482
...process . env ,
477
483
TS_NODE_COMPILER_OPTIONS : '{"typeRoots": ["env-typeroots"]}'
@@ -485,33 +491,38 @@ describe('ts-node', function () {
485
491
} )
486
492
487
493
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 ) {
489
495
expect ( err ) . to . equal ( null )
490
496
const { options, config } = JSON . parse ( stdout )
491
497
expect ( config . options . typeRoots ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/tsconfig-typeroots' ) . replace ( / \\ / g, '/' ) ] )
492
498
expect ( config . options . types ) . to . deep . equal ( [ 'tsconfig-tsnode-types' ] )
493
499
expect ( options . pretty ) . to . equal ( undefined )
494
500
expect ( options . skipIgnore ) . to . equal ( false )
495
501
expect ( options . transpileOnly ) . to . equal ( true )
502
+ expect ( options . require ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/required1.js' ) ] )
496
503
return done ( )
497
504
} )
498
505
} )
499
506
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 ) {
502
509
expect ( err ) . to . equal ( null )
503
510
const { options, config } = JSON . parse ( stdout )
504
511
expect ( config . options . typeRoots ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/tsconfig-typeroots' ) . replace ( / \\ / g, '/' ) ] )
505
512
expect ( config . options . types ) . to . deep . equal ( [ 'flags-types' ] )
506
513
expect ( options . pretty ) . to . equal ( undefined )
507
514
expect ( options . skipIgnore ) . to . equal ( true )
508
515
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
+ ] )
509
520
return done ( )
510
521
} )
511
522
} )
512
523
513
524
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` , {
515
526
env : {
516
527
...process . env ,
517
528
TS_NODE_PRETTY : 'true' ,
@@ -525,6 +536,7 @@ describe('ts-node', function () {
525
536
expect ( options . pretty ) . to . equal ( true )
526
537
expect ( options . skipIgnore ) . to . equal ( false )
527
538
expect ( options . transpileOnly ) . to . equal ( true )
539
+ expect ( options . require ) . to . deep . equal ( [ join ( __dirname , '../tests/tsconfig-options/required1.js' ) ] )
528
540
return done ( )
529
541
} )
530
542
} )
@@ -724,7 +736,7 @@ describe('ts-node', function () {
724
736
describe ( 'esm' , ( ) => {
725
737
this . slow ( 1000 )
726
738
727
- const cmd = `node --loader ts-node/esm.mjs `
739
+ const cmd = `node --loader ts-node/esm`
728
740
729
741
if ( semver . gte ( process . version , '13.0.0' ) ) {
730
742
it ( 'should compile and execute as ESM' , ( done ) => {
@@ -735,6 +747,27 @@ describe('ts-node', function () {
735
747
return done ( )
736
748
} )
737
749
} )
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
+ } )
738
771
739
772
describe ( 'supports experimental-specifier-resolution=node' , ( ) => {
740
773
it ( 'via --experimental-specifier-resolution' , ( done ) => {
0 commit comments