@@ -44,6 +44,18 @@ namespace ts.projectSystem {
4444 } ) ;
4545 }
4646
47+ function trackingLogger ( ) : { log ( message : string ) : void , finish ( ) : string [ ] } {
48+ const logs : string [ ] = [ ] ;
49+ return {
50+ log ( message ) {
51+ logs . push ( message ) ;
52+ } ,
53+ finish ( ) {
54+ return logs ;
55+ }
56+ } ;
57+ }
58+
4759 import typingsName = TI . typingsName ;
4860
4961 describe ( "local module" , ( ) => {
@@ -1031,7 +1043,12 @@ namespace ts.projectSystem {
10311043 const cache = createMap < string > ( ) ;
10321044
10331045 const host = createServerHost ( [ app , jquery , chroma ] ) ;
1034- const result = JsTyping . discoverTypings ( host , [ app . path , jquery . path , chroma . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ ] ) ;
1046+ const logger = trackingLogger ( ) ;
1047+ const result = JsTyping . discoverTypings ( host , logger . log , [ app . path , jquery . path , chroma . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ ] ) ;
1048+ assert . deepEqual ( logger . finish ( ) , [
1049+ 'Inferred typings from file names: ["jquery","chroma-js"]' ,
1050+ 'Result: {"cachedTypingPaths":[],"newTypingNames":["jquery","chroma-js"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1051+ ] ) ;
10351052 assert . deepEqual ( result . newTypingNames , [ "jquery" , "chroma-js" ] ) ;
10361053 } ) ;
10371054
@@ -1044,7 +1061,12 @@ namespace ts.projectSystem {
10441061 const cache = createMap < string > ( ) ;
10451062
10461063 for ( const name of JsTyping . nodeCoreModuleList ) {
1047- const result = JsTyping . discoverTypings ( host , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ name , "somename" ] ) ;
1064+ const logger = trackingLogger ( ) ;
1065+ const result = JsTyping . discoverTypings ( host , logger . log , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ name , "somename" ] ) ;
1066+ assert . deepEqual ( logger . finish ( ) , [
1067+ 'Inferred typings from unresolved imports: ["node","somename"]' ,
1068+ 'Result: {"cachedTypingPaths":[],"newTypingNames":["node","somename"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1069+ ] ) ;
10481070 assert . deepEqual ( result . newTypingNames . sort ( ) , [ "node" , "somename" ] ) ;
10491071 }
10501072 } ) ;
@@ -1060,7 +1082,12 @@ namespace ts.projectSystem {
10601082 } ;
10611083 const host = createServerHost ( [ f , node ] ) ;
10621084 const cache = createMapFromTemplate < string > ( { "node" : node . path } ) ;
1063- const result = JsTyping . discoverTypings ( host , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ "fs" , "bar" ] ) ;
1085+ const logger = trackingLogger ( ) ;
1086+ const result = JsTyping . discoverTypings ( host , logger . log , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ "fs" , "bar" ] ) ;
1087+ assert . deepEqual ( logger . finish ( ) , [
1088+ 'Inferred typings from unresolved imports: ["node","bar"]' ,
1089+ 'Result: {"cachedTypingPaths":["/a/b/node.d.ts"],"newTypingNames":["bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1090+ ] ) ;
10641091 assert . deepEqual ( result . cachedTypingPaths , [ node . path ] ) ;
10651092 assert . deepEqual ( result . newTypingNames , [ "bar" ] ) ;
10661093 } ) ;
@@ -1080,7 +1107,12 @@ namespace ts.projectSystem {
10801107 } ;
10811108 const host = createServerHost ( [ app , a , b ] ) ;
10821109 const cache = createMap < string > ( ) ;
1083- const result = JsTyping . discoverTypings ( host , [ app . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , /*unresolvedImports*/ [ ] ) ;
1110+ const logger = trackingLogger ( ) ;
1111+ const result = JsTyping . discoverTypings ( host , logger . log , [ app . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , /*unresolvedImports*/ [ ] ) ;
1112+ assert . deepEqual ( logger . finish ( ) , [
1113+ 'Searching for typing names in /node_modules; all files: ["/node_modules/a/package.json"]' ,
1114+ 'Result: {"cachedTypingPaths":[],"newTypingNames":["a"],"filesToWatch":["/bower_components","/node_modules"]}' ,
1115+ ] ) ;
10841116 assert . deepEqual ( result , {
10851117 cachedTypingPaths : [ ] ,
10861118 newTypingNames : [ "a" ] , // But not "b"
0 commit comments