@@ -44,6 +44,18 @@ namespace ts.projectSystem {
44
44
} ) ;
45
45
}
46
46
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
+
47
59
import typingsName = TI . typingsName ;
48
60
49
61
describe ( "local module" , ( ) => {
@@ -1031,7 +1043,12 @@ namespace ts.projectSystem {
1031
1043
const cache = createMap < string > ( ) ;
1032
1044
1033
1045
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
+ ] ) ;
1035
1052
assert . deepEqual ( result . newTypingNames , [ "jquery" , "chroma-js" ] ) ;
1036
1053
} ) ;
1037
1054
@@ -1044,7 +1061,12 @@ namespace ts.projectSystem {
1044
1061
const cache = createMap < string > ( ) ;
1045
1062
1046
1063
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
+ ] ) ;
1048
1070
assert . deepEqual ( result . newTypingNames . sort ( ) , [ "node" , "somename" ] ) ;
1049
1071
}
1050
1072
} ) ;
@@ -1060,7 +1082,12 @@ namespace ts.projectSystem {
1060
1082
} ;
1061
1083
const host = createServerHost ( [ f , node ] ) ;
1062
1084
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
+ ] ) ;
1064
1091
assert . deepEqual ( result . cachedTypingPaths , [ node . path ] ) ;
1065
1092
assert . deepEqual ( result . newTypingNames , [ "bar" ] ) ;
1066
1093
} ) ;
@@ -1080,7 +1107,12 @@ namespace ts.projectSystem {
1080
1107
} ;
1081
1108
const host = createServerHost ( [ app , a , b ] ) ;
1082
1109
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
+ ] ) ;
1084
1116
assert . deepEqual ( result , {
1085
1117
cachedTypingPaths : [ ] ,
1086
1118
newTypingNames : [ "a" ] , // But not "b"
0 commit comments