@@ -39,6 +39,7 @@ before(async function () {
39
39
40
40
describe ( 'ts-node' , function ( ) {
41
41
const cmd = `"${ BIN_PATH } " --project "${ PROJECT } "`
42
+ const cmdNoProject = `"${ BIN_PATH } "`
42
43
43
44
this . timeout ( 10000 )
44
45
@@ -88,6 +89,32 @@ describe('ts-node', function () {
88
89
} )
89
90
} )
90
91
92
+ it ( 'shows usage via --help' , function ( done ) {
93
+ exec ( `${ cmdNoProject } --help` , function ( err , stdout ) {
94
+ expect ( err ) . to . equal ( null )
95
+ expect ( stdout ) . to . match ( / U s a g e : t s - n o d e / )
96
+ return done ( )
97
+ } )
98
+ } )
99
+ it ( 'shows version via -v' , function ( done ) {
100
+ exec ( `${ cmdNoProject } -v` , function ( err , stdout ) {
101
+ expect ( err ) . to . equal ( null )
102
+ expect ( stdout . trim ( ) ) . to . equal ( 'v' + testsDirRequire ( 'ts-node/package' ) . version )
103
+ return done ( )
104
+ } )
105
+ } )
106
+ it ( 'shows version of compiler via -vv' , function ( done ) {
107
+ exec ( `${ cmdNoProject } -vv` , function ( err , stdout ) {
108
+ expect ( err ) . to . equal ( null )
109
+ expect ( stdout . trim ( ) ) . to . equal (
110
+ `ts-node v${ testsDirRequire ( 'ts-node/package' ) . version } \n` +
111
+ `node ${ process . version } \n` +
112
+ `compiler v${ testsDirRequire ( 'typescript/package' ) . version } `
113
+ )
114
+ return done ( )
115
+ } )
116
+ } )
117
+
91
118
it ( 'should register via cli' , function ( done ) {
92
119
exec ( `node -r ts-node/register hello-world.ts` , {
93
120
cwd : TEST_DIR
@@ -727,11 +754,30 @@ describe('ts-node', function () {
727
754
} )
728
755
729
756
describe ( 'create' , ( ) => {
757
+ let service : tsNodeTypes . Register
758
+ before ( ( ) => {
759
+ service = create ( { compilerOptions : { target : 'es5' } , skipProject : true } )
760
+ } )
761
+
730
762
it ( 'should create generic compiler instances' , ( ) => {
731
- const service = create ( { compilerOptions : { target : 'es5' } , skipProject : true } )
732
763
const output = service . compile ( 'const x = 10' , 'test.ts' )
733
764
expect ( output ) . to . contain ( 'var x = 10;' )
734
765
} )
766
+
767
+ describe ( 'should get type information' , ( ) => {
768
+ it ( 'given position of identifier' , ( ) => {
769
+ expect ( service . getTypeInfo ( '/**jsdoc here*/const x = 10' , 'test.ts' , 21 ) ) . to . deep . equal ( {
770
+ comment : 'jsdoc here' ,
771
+ name : 'const x: 10'
772
+ } )
773
+ } )
774
+ it ( 'given position that does not point to an identifier' , ( ) => {
775
+ expect ( service . getTypeInfo ( '/**jsdoc here*/const x = 10' , 'test.ts' , 0 ) ) . to . deep . equal ( {
776
+ comment : '' ,
777
+ name : ''
778
+ } )
779
+ } )
780
+ } )
735
781
} )
736
782
737
783
describe ( 'issue #1098' , ( ) => {
@@ -824,6 +870,17 @@ describe('ts-node', function () {
824
870
} )
825
871
} )
826
872
873
+ it ( 'defers to fallback loaders when URL should not be handled by ts-node' , function ( done ) {
874
+ exec ( `${ cmd } index.mjs` , {
875
+ cwd : join ( __dirname , '../tests/esm-import-http-url' )
876
+ } , function ( err , stdout , stderr ) {
877
+ expect ( err ) . to . not . equal ( null )
878
+ // expect error from node's default resolver
879
+ expect ( stderr ) . to . match ( / E r r o r \[ E R R _ U N S U P P O R T E D _ E S M _ U R L _ S C H E M E \] : .* \n * a t d e f a u l t R e s o l v e / )
880
+ return done ( )
881
+ } )
882
+ } )
883
+
827
884
it ( 'should support transpile only mode via dedicated loader entrypoint' , ( done ) => {
828
885
exec ( `${ cmd } /transpile-only index.ts` , { cwd : join ( __dirname , '../tests/esm-transpile-only' ) } , function ( err , stdout ) {
829
886
expect ( err ) . to . equal ( null )
0 commit comments