@@ -195,7 +195,8 @@ namespace ts {
195
195
196
196
describe ( "Node module resolution - non-relative paths" , ( ) => {
197
197
it ( "computes correct commonPrefix for moduleName cache" , ( ) => {
198
- const cache = createModuleResolutionCache ( "/" , ( f ) => f ) . getOrCreateCacheForModuleName ( "a" ) ;
198
+ const resolutionCache = createModuleResolutionCache ( "/" , ( f ) => f ) ;
199
+ let cache = resolutionCache . getOrCreateCacheForModuleName ( "a" ) ;
199
200
cache . set ( "/sub" , {
200
201
resolvedModule : {
201
202
originalPath : undefined ,
@@ -207,6 +208,62 @@ namespace ts {
207
208
} ) ;
208
209
assert . isDefined ( cache . get ( "/sub" ) ) ;
209
210
assert . isUndefined ( cache . get ( "/" ) ) ;
211
+
212
+ cache = resolutionCache . getOrCreateCacheForModuleName ( "b" ) ;
213
+ cache . set ( "/sub/dir/foo" , {
214
+ resolvedModule : {
215
+ originalPath : undefined ,
216
+ resolvedFileName : "/sub/directory/node_modules/b/index.ts" ,
217
+ isExternalLibraryImport : true ,
218
+ extension : Extension . Ts ,
219
+ } ,
220
+ failedLookupLocations : [ ] ,
221
+ } ) ;
222
+ assert . isDefined ( cache . get ( "/sub/dir/foo" ) ) ;
223
+ assert . isDefined ( cache . get ( "/sub/dir" ) ) ;
224
+ assert . isDefined ( cache . get ( "/sub" ) ) ;
225
+ assert . isUndefined ( cache . get ( "/" ) ) ;
226
+
227
+ cache = resolutionCache . getOrCreateCacheForModuleName ( "c" ) ;
228
+ cache . set ( "/foo/bar" , {
229
+ resolvedModule : {
230
+ originalPath : undefined ,
231
+ resolvedFileName : "/bar/node_modules/c/index.ts" ,
232
+ isExternalLibraryImport : true ,
233
+ extension : Extension . Ts ,
234
+ } ,
235
+ failedLookupLocations : [ ] ,
236
+ } ) ;
237
+ assert . isDefined ( cache . get ( "/foo/bar" ) ) ;
238
+ assert . isDefined ( cache . get ( "/foo" ) ) ;
239
+ assert . isDefined ( cache . get ( "/" ) ) ;
240
+
241
+ cache = resolutionCache . getOrCreateCacheForModuleName ( "d" ) ;
242
+ cache . set ( "/foo" , {
243
+ resolvedModule : {
244
+ originalPath : undefined ,
245
+ resolvedFileName : "/foo/index.ts" ,
246
+ isExternalLibraryImport : true ,
247
+ extension : Extension . Ts ,
248
+ } ,
249
+ failedLookupLocations : [ ] ,
250
+ } ) ;
251
+ assert . isDefined ( cache . get ( "/foo" ) ) ;
252
+ assert . isUndefined ( cache . get ( "/" ) ) ;
253
+
254
+ cache = resolutionCache . getOrCreateCacheForModuleName ( "e" ) ;
255
+ cache . set ( "c:/foo" , {
256
+ resolvedModule : {
257
+ originalPath : undefined ,
258
+ resolvedFileName : "d:/bar/node_modules/e/index.ts" ,
259
+ isExternalLibraryImport : true ,
260
+ extension : Extension . Ts ,
261
+ } ,
262
+ failedLookupLocations : [ ] ,
263
+ } ) ;
264
+ assert . isDefined ( cache . get ( "c:/foo" ) ) ;
265
+ assert . isUndefined ( cache . get ( "c:/" ) ) ;
266
+ assert . isUndefined ( cache . get ( "d:/" ) ) ;
210
267
} ) ;
211
268
212
269
it ( "load module as file - ts files not loaded" , ( ) => {
0 commit comments