@@ -975,5 +975,34 @@ export const x = 10;`
975975 host . checkTimeoutQueueLength ( 0 ) ;
976976 } ) ;
977977 } ) ;
978+
979+ describe ( "avoid unnecessary invalidation" , ( ) => {
980+ it ( "unnecessary lookup invalidation on save" , ( ) => {
981+ const expectedNonRelativeDirectories = [ `${ projectLocation } /node_modules` , `${ projectLocation } /src` ] ;
982+ const module1Name = "module1" ;
983+ const module2Name = "module2" ;
984+ const fileContent = `import { module1 } from "${ module1Name } ";import { module2 } from "${ module2Name } ";` ;
985+ const file1 : File = {
986+ path : `${ projectLocation } /src/file1.ts` ,
987+ content : fileContent
988+ } ;
989+ const { module1, module2 } = getModules ( `${ projectLocation } /src/node_modules/module1/index.ts` , `${ projectLocation } /node_modules/module2/index.ts` ) ;
990+ const files = [ module1 , module2 , file1 , configFile , libFile ] ;
991+ const host = createServerHost ( files ) ;
992+ const resolutionTrace = createHostModuleResolutionTrace ( host ) ;
993+ const service = createProjectService ( host ) ;
994+ service . openClientFile ( file1 . path ) ;
995+ const project = service . configuredProjects . get ( configFile . path ) ! ;
996+ ( project as ResolutionCacheHost ) . maxNumberOfFilesToIterateForInvalidation = 1 ;
997+ const expectedTrace = getExpectedNonRelativeModuleResolutionTrace ( host , file1 , module1 , module1Name ) ;
998+ getExpectedNonRelativeModuleResolutionTrace ( host , file1 , module2 , module2Name , expectedTrace ) ;
999+ verifyTrace ( resolutionTrace , expectedTrace ) ;
1000+ verifyWatchesWithConfigFile ( host , files , file1 , expectedNonRelativeDirectories ) ;
1001+
1002+ // invoke callback to simulate saving
1003+ host . modifyFile ( file1 . path , file1 . content , { invokeFileDeleteCreateAsPartInsteadOfChange : true } ) ;
1004+ host . checkTimeoutQueueLengthAndRun ( 0 ) ;
1005+ } ) ;
1006+ } ) ;
9781007 } ) ;
9791008}
0 commit comments