@@ -9,21 +9,40 @@ namespace ts.projectSystem {
9
9
const file1 : File = {
10
10
path : `${ tscWatch . projectRoot } /file1.ts` ,
11
11
content : `import { foo } from "module1";
12
- foo();`
12
+ foo();
13
+ import { bar } from "./file2";
14
+ bar();`
13
15
} ;
14
16
const file2 : File = {
15
17
path : `${ tscWatch . projectRoot } /file2.ts` ,
16
- content : `${ file1 . content }
17
- export function bar(){}`
18
+ content : `export function bar(){}`
18
19
} ;
19
20
const moduleFile : File = {
20
21
path : `${ tscWatch . projectRoot } /node_modules/module1/index.d.ts` ,
21
22
content : `export function foo(): string;`
22
23
} ;
23
24
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
+
24
42
it ( "configured project" , ( ) => {
25
43
const host = createServerHost ( [ configFile , libFile , file1 , file2 ] ) ;
26
44
const service = createProjectService ( host ) ;
45
+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
27
46
service . openClientFile ( file1 . path ) ;
28
47
checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
29
48
const project = service . configuredProjects . get ( configFile . path ) ! ;
@@ -37,18 +56,21 @@ namespace ts.projectSystem {
37
56
checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
38
57
assert . strictEqual ( service . configuredProjects . get ( configFile . path ) , project ) ;
39
58
checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , configFile . path , moduleFile . path ] ) ;
59
+
60
+ verifyFileUpdates ( host , service , project ) ;
40
61
} ) ;
41
62
42
63
it ( "inferred project" , ( ) => {
43
64
const host = createServerHost ( [ libFile , file1 , file2 ] ) ;
44
65
const service = createProjectService ( host , /*parameters*/ undefined , { useInferredProjectPerProjectRoot : true , } ) ;
66
+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
45
67
const timeoutId = host . getNextTimeoutId ( ) ;
46
68
service . setCompilerOptionsForInferredProjects ( { excludeDirectories : [ "node_modules" ] } , tscWatch . projectRoot ) ;
47
69
host . clearTimeout ( timeoutId ) ;
48
70
service . openClientFile ( file1 . path , /*fileContent*/ undefined , /*scriptKind*/ undefined , tscWatch . projectRoot ) ;
49
71
checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
50
72
const project = service . inferredProjects [ 0 ] ;
51
- checkProjectActualFiles ( project , [ libFile . path , file1 . path ] ) ;
73
+ checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path ] ) ;
52
74
53
75
// Install module1
54
76
host . ensureFileOrFolder ( moduleFile ) ;
@@ -57,12 +79,15 @@ namespace ts.projectSystem {
57
79
service . reloadProjects ( ) ;
58
80
checkNumberOfProjects ( service , { inferredProjects : 1 } ) ;
59
81
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 ) ;
61
85
} ) ;
62
86
63
87
it ( "external project" , ( ) => {
64
88
const host = createServerHost ( [ libFile , file1 , file2 ] ) ;
65
89
const service = createProjectService ( host ) ;
90
+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
66
91
service . openExternalProject ( {
67
92
projectFileName : `${ tscWatch . projectRoot } /project.sln` ,
68
93
options : { excludeDirectories : [ "node_modules" ] } ,
@@ -81,11 +106,14 @@ namespace ts.projectSystem {
81
106
checkNumberOfProjects ( service , { externalProjects : 1 } ) ;
82
107
assert . strictEqual ( service . externalProjects [ 0 ] , project ) ;
83
108
checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , moduleFile . path ] ) ;
109
+
110
+ verifyFileUpdates ( host , service , project ) ;
84
111
} ) ;
85
112
86
113
it ( "external project with config file" , ( ) => {
87
114
const host = createServerHost ( [ libFile , file1 , file2 , configFile ] ) ;
88
115
const service = createProjectService ( host ) ;
116
+ service . setHostConfiguration ( { watchOptions : { excludeFiles : [ file2 . path ] } } ) ;
89
117
service . openExternalProject ( {
90
118
projectFileName : `${ tscWatch . projectRoot } /project.sln` ,
91
119
options : { excludeDirectories : [ "node_modules" ] } ,
@@ -104,6 +132,8 @@ namespace ts.projectSystem {
104
132
checkNumberOfProjects ( service , { configuredProjects : 1 } ) ;
105
133
assert . strictEqual ( service . configuredProjects . get ( configFile . path ) , project ) ;
106
134
checkProjectActualFiles ( project , [ libFile . path , file1 . path , file2 . path , configFile . path , moduleFile . path ] ) ;
135
+
136
+ verifyFileUpdates ( host , service , project ) ;
107
137
} ) ;
108
138
} ) ;
109
139
}
0 commit comments