@@ -5,6 +5,7 @@ import { tmpdir } from 'os';
5
5
import semver = require( 'semver' ) ;
6
6
import {
7
7
BIN_PATH_JS ,
8
+ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG ,
8
9
nodeSupportsEsmHooks ,
9
10
ts ,
10
11
tsSupportsShowConfig ,
@@ -143,7 +144,10 @@ test.suite('ts-node', (test) => {
143
144
144
145
test ( 'should execute cli with absolute path' , async ( ) => {
145
146
const { err, stdout } = await exec (
146
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } "${ join ( TEST_DIR , 'hello-world' ) } "`
147
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } "${ join (
148
+ TEST_DIR ,
149
+ 'hello-world'
150
+ ) } "`
147
151
) ;
148
152
expect ( err ) . toBe ( null ) ;
149
153
expect ( stdout ) . toBe ( 'Hello, world!\n' ) ;
@@ -157,26 +161,18 @@ test.suite('ts-node', (test) => {
157
161
expect ( stdout ) . toBe ( 'example\n' ) ;
158
162
} ) ;
159
163
160
- test ( ' should provide registered information globally' , async ( ) => {
164
+ test ( " should expose ts-node Service as a symbol property on Node's `process` object" , async ( ) => {
161
165
const { err, stdout } = await exec (
162
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } env`
166
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } env`
163
167
) ;
164
168
expect ( err ) . toBe ( null ) ;
165
169
expect ( stdout ) . toBe ( 'object\n' ) ;
166
170
} ) ;
167
171
168
- test ( 'should provide registered information on register' , async ( ) => {
169
- const { err, stdout } = await exec ( `node -r ts-node/register env.ts` , {
170
- cwd : TEST_DIR ,
171
- } ) ;
172
- expect ( err ) . toBe ( null ) ;
173
- expect ( stdout ) . toBe ( 'object\n' ) ;
174
- } ) ;
175
-
176
172
test ( 'should allow js' , async ( ) => {
177
173
const { err, stdout } = await exec (
178
174
[
179
- CMD_TS_NODE_WITH_PROJECT_FLAG ,
175
+ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG ,
180
176
'-O "{\\"allowJs\\":true}"' ,
181
177
'-pe "import { main } from \'./allow-js/run\';main()"' ,
182
178
] . join ( ' ' )
@@ -188,7 +184,7 @@ test.suite('ts-node', (test) => {
188
184
test ( 'should include jsx when `allow-js` true' , async ( ) => {
189
185
const { err, stdout } = await exec (
190
186
[
191
- CMD_TS_NODE_WITH_PROJECT_FLAG ,
187
+ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG ,
192
188
'-O "{\\"allowJs\\":true}"' ,
193
189
'-pe "import { Foo2 } from \'./allow-js/with-jsx\'; Foo2.sayHi()"' ,
194
190
] . join ( ' ' )
@@ -199,21 +195,21 @@ test.suite('ts-node', (test) => {
199
195
200
196
test ( 'should eval code' , async ( ) => {
201
197
const { err, stdout } = await exec (
202
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } -e "import * as m from './module';console.log(m.example('test'))"`
198
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } -e "import * as m from './module';console.log(m.example('test'))"`
203
199
) ;
204
200
expect ( err ) . toBe ( null ) ;
205
201
expect ( stdout ) . toBe ( 'TEST\n' ) ;
206
202
} ) ;
207
203
208
204
test ( 'should import empty files' , async ( ) => {
209
205
const { err, stdout } = await exec (
210
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } -e "import './empty'"`
206
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } -e "import './empty'"`
211
207
) ;
212
208
expect ( err ) . toBe ( null ) ;
213
209
expect ( stdout ) . toBe ( '' ) ;
214
210
} ) ;
215
211
216
- test ( 'should throw errors' , async ( ) => {
212
+ test ( 'should throw typechecking errors' , async ( ) => {
217
213
const { err } = await exec (
218
214
`${ CMD_TS_NODE_WITH_PROJECT_FLAG } -e "import * as m from './module';console.log(m.example(123))"`
219
215
) ;
@@ -377,15 +373,17 @@ test.suite('ts-node', (test) => {
377
373
}
378
374
379
375
test ( 'should pipe into `ts-node` and evaluate' , async ( ) => {
380
- const execPromise = exec ( CMD_TS_NODE_WITH_PROJECT_FLAG ) ;
376
+ const execPromise = exec ( CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG ) ;
381
377
execPromise . child . stdin ! . end ( "console.log('hello')" ) ;
382
378
const { err, stdout } = await execPromise ;
383
379
expect ( err ) . toBe ( null ) ;
384
380
expect ( stdout ) . toBe ( 'hello\n' ) ;
385
381
} ) ;
386
382
387
383
test ( 'should pipe into `ts-node`' , async ( ) => {
388
- const execPromise = exec ( `${ CMD_TS_NODE_WITH_PROJECT_FLAG } -p` ) ;
384
+ const execPromise = exec (
385
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } -p`
386
+ ) ;
389
387
execPromise . child . stdin ! . end ( 'true' ) ;
390
388
const { err, stdout } = await execPromise ;
391
389
expect ( err ) . toBe ( null ) ;
@@ -404,15 +402,15 @@ test.suite('ts-node', (test) => {
404
402
405
403
test ( 'should support require flags' , async ( ) => {
406
404
const { err, stdout } = await exec (
407
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } -r ./hello-world -pe "console.log('success')"`
405
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } -r ./hello-world -pe "console.log('success')"`
408
406
) ;
409
407
expect ( err ) . toBe ( null ) ;
410
408
expect ( stdout ) . toBe ( 'Hello, world!\nsuccess\nundefined\n' ) ;
411
409
} ) ;
412
410
413
411
test ( 'should support require from node modules' , async ( ) => {
414
412
const { err, stdout } = await exec (
415
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } -r typescript -e "console.log('success')"`
413
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } -r typescript -e "console.log('success')"`
416
414
) ;
417
415
expect ( err ) . toBe ( null ) ;
418
416
expect ( stdout ) . toBe ( 'success\n' ) ;
@@ -458,36 +456,25 @@ test.suite('ts-node', (test) => {
458
456
) ;
459
457
} ) ;
460
458
461
- test ( 'should preserve `ts-node` context with child process' , async ( ) => {
462
- const { err, stdout } = await exec (
463
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } child-process`
464
- ) ;
465
- expect ( err ) . toBe ( null ) ;
466
- expect ( stdout ) . toBe ( 'Hello, world!\n' ) ;
467
- } ) ;
468
-
469
459
test ( 'should import js before ts by default' , async ( ) => {
470
460
const { err, stdout } = await exec (
471
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } import-order/compiled`
461
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } import-order/compiled`
472
462
) ;
473
463
expect ( err ) . toBe ( null ) ;
474
464
expect ( stdout ) . toBe ( 'Hello, JavaScript!\n' ) ;
475
465
} ) ;
476
466
477
- const preferTsExtsEntrypoint = semver . gte ( process . version , '12.0.0' )
478
- ? 'import-order/compiled'
479
- : 'import-order/require-compiled' ;
480
467
test ( 'should import ts before js when --prefer-ts-exts flag is present' , async ( ) => {
481
468
const { err, stdout } = await exec (
482
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } --prefer-ts-exts ${ preferTsExtsEntrypoint } `
469
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } --prefer-ts-exts import-order/compiled `
483
470
) ;
484
471
expect ( err ) . toBe ( null ) ;
485
472
expect ( stdout ) . toBe ( 'Hello, TypeScript!\n' ) ;
486
473
} ) ;
487
474
488
475
test ( 'should import ts before js when TS_NODE_PREFER_TS_EXTS env is present' , async ( ) => {
489
476
const { err, stdout } = await exec (
490
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } ${ preferTsExtsEntrypoint } ` ,
477
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } import-order/compiled ` ,
491
478
{
492
479
env : { ...process . env , TS_NODE_PREFER_TS_EXTS : 'true' } ,
493
480
}
@@ -498,7 +485,7 @@ test.suite('ts-node', (test) => {
498
485
499
486
test ( 'should ignore .d.ts files' , async ( ) => {
500
487
const { err, stdout } = await exec (
501
- `${ CMD_TS_NODE_WITH_PROJECT_FLAG } import-order/importer`
488
+ `${ CMD_TS_NODE_WITH_PROJECT_TRANSPILE_ONLY_FLAG } import-order/importer`
502
489
) ;
503
490
expect ( err ) . toBe ( null ) ;
504
491
expect ( stdout ) . toBe ( 'Hello, World!\n' ) ;
@@ -538,63 +525,60 @@ test.suite('ts-node', (test) => {
538
525
} ) ;
539
526
} ) ;
540
527
541
- if ( semver . gte ( ts . version , '2.7.0' ) ) {
542
- test ( 'should locate tsconfig relative to entry-point by default' , async ( ) => {
543
- const { err, stdout } = await exec ( `${ BIN_PATH } ../a/index` , {
544
- cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
545
- } ) ;
546
- expect ( err ) . toBe ( null ) ;
547
- expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
528
+ test ( 'should locate tsconfig relative to entry-point by default' , async ( ) => {
529
+ const { err, stdout } = await exec ( `${ BIN_PATH } ../a/index` , {
530
+ cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
548
531
} ) ;
549
- test ( 'should locate tsconfig relative to entry-point via ts-node-script' , async ( ) => {
550
- const { err, stdout } = await exec ( `${ BIN_SCRIPT_PATH } ../a/index` , {
551
- cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
552
- } ) ;
553
- expect ( err ) . toBe ( null ) ;
554
- expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
555
- } ) ;
556
- test ( 'should locate tsconfig relative to entry-point with --script-mode' , async ( ) => {
557
- const { err, stdout } = await exec (
558
- `${ BIN_PATH } --script-mode ../a/index` ,
559
- {
560
- cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
561
- }
562
- ) ;
563
- expect ( err ) . toBe ( null ) ;
564
- expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
532
+ expect ( err ) . toBe ( null ) ;
533
+ expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
534
+ } ) ;
535
+ test ( 'should locate tsconfig relative to entry-point via ts-node-script' , async ( ) => {
536
+ const { err, stdout } = await exec ( `${ BIN_SCRIPT_PATH } ../a/index` , {
537
+ cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
565
538
} ) ;
566
- test ( 'should locate tsconfig relative to cwd via ts-node-cwd' , async ( ) => {
567
- const { err, stdout } = await exec ( `${ BIN_CWD_PATH } ../a/index` , {
539
+ expect ( err ) . toBe ( null ) ;
540
+ expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
541
+ } ) ;
542
+ test ( 'should locate tsconfig relative to entry-point with --script-mode' , async ( ) => {
543
+ const { err, stdout } = await exec (
544
+ `${ BIN_PATH } --script-mode ../a/index` ,
545
+ {
568
546
cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
569
- } ) ;
570
- expect ( err ) . toBe ( null ) ;
571
- expect ( stdout ) . toMatch ( / p l u g i n - b / ) ;
547
+ }
548
+ ) ;
549
+ expect ( err ) . toBe ( null ) ;
550
+ expect ( stdout ) . toMatch ( / p l u g i n - a / ) ;
551
+ } ) ;
552
+ test ( 'should locate tsconfig relative to cwd via ts-node-cwd' , async ( ) => {
553
+ const { err, stdout } = await exec ( `${ BIN_CWD_PATH } ../a/index` , {
554
+ cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
572
555
} ) ;
573
- test ( 'should locate tsconfig relative to cwd in --cwd-mode' , async ( ) => {
556
+ expect ( err ) . toBe ( null ) ;
557
+ expect ( stdout ) . toMatch ( / p l u g i n - b / ) ;
558
+ } ) ;
559
+ test ( 'should locate tsconfig relative to cwd in --cwd-mode' , async ( ) => {
560
+ const { err, stdout } = await exec ( `${ BIN_PATH } --cwd-mode ../a/index` , {
561
+ cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) ,
562
+ } ) ;
563
+ expect ( err ) . toBe ( null ) ;
564
+ expect ( stdout ) . toMatch ( / p l u g i n - b / ) ;
565
+ } ) ;
566
+ test ( 'should locate tsconfig relative to realpath, not symlink, when entrypoint is a symlink' , async ( t ) => {
567
+ if (
568
+ lstatSync (
569
+ join ( TEST_DIR , 'main-realpath/symlink/symlink.tsx' )
570
+ ) . isSymbolicLink ( )
571
+ ) {
574
572
const { err, stdout } = await exec (
575
- `${ BIN_PATH } --cwd-mode ../a/index` ,
576
- { cwd : join ( TEST_DIR , 'cwd-and-script-mode/b' ) }
573
+ `${ BIN_PATH } main-realpath/symlink/symlink.tsx`
577
574
) ;
578
575
expect ( err ) . toBe ( null ) ;
579
- expect ( stdout ) . toMatch ( / p l u g i n - b / ) ;
580
- } ) ;
581
- test ( 'should locate tsconfig relative to realpath, not symlink, when entrypoint is a symlink' , async ( t ) => {
582
- if (
583
- lstatSync (
584
- join ( TEST_DIR , 'main-realpath/symlink/symlink.tsx' )
585
- ) . isSymbolicLink ( )
586
- ) {
587
- const { err, stdout } = await exec (
588
- `${ BIN_PATH } main-realpath/symlink/symlink.tsx`
589
- ) ;
590
- expect ( err ) . toBe ( null ) ;
591
- expect ( stdout ) . toBe ( '' ) ;
592
- } else {
593
- t . log ( 'Skipping' ) ;
594
- return ;
595
- }
596
- } ) ;
597
- }
576
+ expect ( stdout ) . toBe ( '' ) ;
577
+ } else {
578
+ t . log ( 'Skipping' ) ;
579
+ return ;
580
+ }
581
+ } ) ;
598
582
599
583
test . suite ( 'should read ts-node options from tsconfig.json' , ( test ) => {
600
584
const BIN_EXEC = `"${ BIN_PATH } " --project tsconfig-options/tsconfig.json` ;
0 commit comments