@@ -9,21 +9,40 @@ namespace ts.projectSystem {
99 const file1 : File = {
1010 path : `${ tscWatch . projectRoot } /file1.ts` ,
1111 content : `import { foo } from "module1";
12- foo();`
12+ foo();
13+ import { bar } from "./file2";
14+ bar();`
1315 } ;
1416 const file2 : File = {
1517 path : `${ tscWatch . projectRoot } /file2.ts` ,
16- content : `${ file1 . content }
17- export function bar(){}`
18+ content : `export function bar(){}`
1819 } ;
1920 const moduleFile : File = {
2021 path : `${ tscWatch . projectRoot } /node_modules/module1/index.d.ts` ,
2122 content : `export function foo(): string;`
2223 } ;
2324
25+ function verifyFileUpdates ( host : TestServerHost , service : TestProjectService , project : server . Project ) {
26+ // update file
27+ const updatedText = `${ file2 . content }
28+ bar();` ;
29+ host . writeFile ( file2 . path , updatedText ) ;
30+ host . checkTimeoutQueueLength ( 0 ) ;
31+ service . reloadProjects ( ) ;
32+ assert . equal ( project . getCurrentProgram ( ) ?. getSourceFile ( file2 . path ) ?. text , updatedText ) ;
33+
34+ // delete file
35+ host . deleteFile ( file2 . path ) ;
36+ host . checkTimeoutQueueLength ( 0 ) ;
37+ service . reloadProjects ( ) ;
38+ assert . isUndefined ( project . getCurrentProgram ( ) ?. getSourceFile ( file2 . path ) ?. text ) ;
39+ assert . isUndefined ( service . getScriptInfo ( file2 . path ) ) ;
40+ }
41+
2442 it ( "configured project" , ( ) => {
2543 const host = createServerHost ( [ configFile , libFile , file1 , file2 ] ) ;
2644 const service = createProjectService ( host ) ;
45+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
2746 service . openClientFile ( file1 . path ) ;
2847 checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
2948 const project = service . configuredProjects . get ( configFile . path ) ! ;
@@ -37,18 +56,21 @@ namespace ts.projectSystem {
3756 checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
3857 assert . strictEqual ( service . configuredProjects . get ( configFile . path ) , project ) ;
3958 checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , configFile . path , moduleFile . path ] ) ;
59+
60+ verifyFileUpdates ( host , service , project ) ;
4061 } ) ;
4162
4263 it ( "inferred project" , ( ) => {
4364 const host = createServerHost ( [ libFile , file1 , file2 ] ) ;
4465 const service = createProjectService ( host , /*parameters*/ undefined , { useInferredProjectPerProjectRoot : true , } ) ;
66+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
4567 const timeoutId = host . getNextTimeoutId ( ) ;
4668 service . setCompilerOptionsForInferredProjects ( { excludeDirectories : [ "node_modules" ] } , tscWatch . projectRoot ) ;
4769 host . clearTimeout ( timeoutId ) ;
4870 service . openClientFile ( file1 . path , /*fileContent*/ undefined , /*scriptKind*/ undefined , tscWatch . projectRoot ) ;
4971 checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
5072 const project = service . inferredProjects [ 0 ] ;
51- checkProjectActualFiles ( project , [ libFile . path , file1 . path ] ) ;
73+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path ] ) ;
5274
5375 // Install module1
5476 host . ensureFileOrFolder ( moduleFile ) ;
@@ -57,12 +79,15 @@ namespace ts.projectSystem {
5779 service . reloadProjects ( ) ;
5880 checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
5981 assert . strictEqual ( service . inferredProjects [ 0 ] , project ) ;
60- checkProjectActualFiles ( project , [ libFile . path , file1 . path , moduleFile . path ] ) ;
82+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , moduleFile . path ] ) ;
83+
84+ verifyFileUpdates ( host , service , project ) ;
6185 } ) ;
6286
6387 it ( "external project" , ( ) => {
6488 const host = createServerHost ( [ libFile , file1 , file2 ] ) ;
6589 const service = createProjectService ( host ) ;
90+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
6691 service . openExternalProject ( {
6792 projectFileName : `${ tscWatch . projectRoot } /project.sln` ,
6893 options : { excludeDirectories : [ "node_modules" ] } ,
@@ -81,11 +106,14 @@ namespace ts.projectSystem {
81106 checkNumberOfProjects ( service , { externalProjects : 1 } ) ;
82107 assert . strictEqual ( service . externalProjects [ 0 ] , project ) ;
83108 checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , moduleFile . path ] ) ;
109+
110+ verifyFileUpdates ( host , service , project ) ;
84111 } ) ;
85112
86113 it ( "external project with config file" , ( ) => {
87114 const host = createServerHost ( [ libFile , file1 , file2 , configFile ] ) ;
88115 const service = createProjectService ( host ) ;
116+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
89117 service . openExternalProject ( {
90118 projectFileName : `${ tscWatch . projectRoot } /project.sln` ,
91119 options : { excludeDirectories : [ "node_modules" ] } ,
@@ -104,6 +132,8 @@ namespace ts.projectSystem {
104132 checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
105133 assert . strictEqual ( service . configuredProjects . get ( configFile . path ) , project ) ;
106134 checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , configFile . path , moduleFile . path ] ) ;
135+
136+ verifyFileUpdates ( host , service , project ) ;
107137 } ) ;
108138 } ) ;
109139}
0 commit comments