@@ -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" , ( ) => {
@@ -1025,7 +1037,12 @@ namespace ts.projectSystem {
10251037 const cache = createMap < string > ( ) ;
10261038
10271039 const host = createServerHost ( [ app , jquery , chroma ] ) ;
1028- const result = JsTyping . discoverTypings ( host , [ app . path , jquery . path , chroma . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ ] ) ;
1040+ const logger = trackingLogger ( ) ;
1041+ const result = JsTyping . discoverTypings ( host , logger . log , [ app . path , jquery . path , chroma . path ] , getDirectoryPath ( < Path > app . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ ] ) ;
1042+ assert . deepEqual ( logger . finish ( ) , [
1043+ 'Inferred typings from file names: ["jquery","chroma-js"]' ,
1044+ 'Result: {"cachedTypingPaths":[],"newTypingNames":["jquery","chroma-js"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1045+ ] ) ;
10291046 assert . deepEqual ( result . newTypingNames , [ "jquery" , "chroma-js" ] ) ;
10301047 } ) ;
10311048
@@ -1038,7 +1055,12 @@ namespace ts.projectSystem {
10381055 const cache = createMap < string > ( ) ;
10391056
10401057 for ( const name of JsTyping . nodeCoreModuleList ) {
1041- const result = JsTyping . discoverTypings ( host , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ name , "somename" ] ) ;
1058+ const logger = trackingLogger ( ) ;
1059+ const result = JsTyping . discoverTypings ( host , logger . log , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ name , "somename" ] ) ;
1060+ assert . deepEqual ( logger . finish ( ) , [
1061+ 'Inferred typings from unresolved imports: ["node","somename"]' ,
1062+ 'Result: {"cachedTypingPaths":[],"newTypingNames":["node","somename"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1063+ ] ) ;
10421064 assert . deepEqual ( result . newTypingNames . sort ( ) , [ "node" , "somename" ] ) ;
10431065 }
10441066 } ) ;
@@ -1054,7 +1076,12 @@ namespace ts.projectSystem {
10541076 } ;
10551077 const host = createServerHost ( [ f , node ] ) ;
10561078 const cache = createMapFromTemplate < string > ( { "node" : node . path } ) ;
1057- const result = JsTyping . discoverTypings ( host , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ "fs" , "bar" ] ) ;
1079+ const logger = trackingLogger ( ) ;
1080+ const result = JsTyping . discoverTypings ( host , logger . log , [ f . path ] , getDirectoryPath ( < Path > f . path ) , /*safeListPath*/ undefined , cache , { enable : true } , [ "fs" , "bar" ] ) ;
1081+ assert . deepEqual ( logger . finish ( ) , [
1082+ 'Inferred typings from unresolved imports: ["node","bar"]' ,
1083+ 'Result: {"cachedTypingPaths":["/a/b/node.d.ts"],"newTypingNames":["bar"],"filesToWatch":["/a/b/bower_components","/a/b/node_modules"]}' ,
1084+ ] ) ;
10581085 assert . deepEqual ( result . cachedTypingPaths , [ node . path ] ) ;
10591086 assert . deepEqual ( result . newTypingNames , [ "bar" ] ) ;
10601087 } ) ;
0 commit comments