@@ -62,13 +62,17 @@ namespace ts.tscWatch {
62
62
return getOutputFileNames ( subProject , baseFileNameWithoutExtension ) . map ( f => [ f , host . getModifiedTime ( f ) ] as OutputFileStamp ) ;
63
63
}
64
64
65
- function getOutputFileStamps ( host : WatchedSystem ) : OutputFileStamp [ ] {
66
- return [
65
+ function getOutputFileStamps ( host : WatchedSystem , additionalFiles ?: ReadonlyArray < [ SubProject , string ] > ) : OutputFileStamp [ ] {
66
+ const result = [
67
67
...getOutputStamps ( host , SubProject . core , "anotherModule" ) ,
68
68
...getOutputStamps ( host , SubProject . core , "index" ) ,
69
69
...getOutputStamps ( host , SubProject . logic , "index" ) ,
70
70
...getOutputStamps ( host , SubProject . tests , "index" ) ,
71
71
] ;
72
+ if ( additionalFiles ) {
73
+ additionalFiles . forEach ( ( [ subProject , baseFileNameWithoutExtension ] ) => result . push ( ...getOutputStamps ( host , subProject , baseFileNameWithoutExtension ) ) ) ;
74
+ }
75
+ return result ;
72
76
}
73
77
74
78
function verifyChangedFiles ( actualStamps : OutputFileStamp [ ] , oldTimeStamps : OutputFileStamp [ ] , changedFiles : string [ ] ) {
@@ -108,49 +112,89 @@ namespace ts.tscWatch {
108
112
createSolutionInWatchMode ( ) ;
109
113
} ) ;
110
114
111
- it ( "change builds changes and reports found errors message" , ( ) => {
112
- const host = createSolutionInWatchMode ( ) ;
113
- verifyChange ( `${ core [ 1 ] . content }
115
+ describe ( "validates the changes and watched files" , ( ) => {
116
+ const newFileWithoutExtension = "newFile" ;
117
+ const newFile : File = {
118
+ path : projectFilePath ( SubProject . core , `${ newFileWithoutExtension } .ts` ) ,
119
+ content : `export const newFileConst = 30;`
120
+ } ;
121
+
122
+ function createSolutionInWatchModeToVerifyChanges ( additionalFiles ?: ReadonlyArray < [ SubProject , string ] > ) {
123
+ const host = createSolutionInWatchMode ( ) ;
124
+ return { host, verifyChangeWithFile, verifyChangeAfterTimeout, verifyWatches } ;
125
+
126
+ function verifyChangeWithFile ( fileName : string , content : string ) {
127
+ const outputFileStamps = getOutputFileStamps ( host , additionalFiles ) ;
128
+ host . writeFile ( fileName , content ) ;
129
+ verifyChangeAfterTimeout ( outputFileStamps ) ;
130
+ }
131
+
132
+ function verifyChangeAfterTimeout ( outputFileStamps : OutputFileStamp [ ] ) {
133
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds core
134
+ const changedCore = getOutputFileStamps ( host , additionalFiles ) ;
135
+ verifyChangedFiles ( changedCore , outputFileStamps , [
136
+ ...getOutputFileNames ( SubProject . core , "anotherModule" ) , // This should not be written really
137
+ ...getOutputFileNames ( SubProject . core , "index" ) ,
138
+ ...( additionalFiles ? getOutputFileNames ( SubProject . core , newFileWithoutExtension ) : emptyArray )
139
+ ] ) ;
140
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds tests
141
+ const changedTests = getOutputFileStamps ( host , additionalFiles ) ;
142
+ verifyChangedFiles ( changedTests , changedCore , [
143
+ ...getOutputFileNames ( SubProject . tests , "index" ) // Again these need not be written
144
+ ] ) ;
145
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds logic
146
+ const changedLogic = getOutputFileStamps ( host , additionalFiles ) ;
147
+ verifyChangedFiles ( changedLogic , changedTests , [
148
+ ...getOutputFileNames ( SubProject . logic , "index" ) // Again these need not be written
149
+ ] ) ;
150
+ host . checkTimeoutQueueLength ( 0 ) ;
151
+ checkOutputErrorsIncremental ( host , emptyArray ) ;
152
+ verifyWatches ( ) ;
153
+ }
154
+
155
+ function verifyWatches ( ) {
156
+ checkWatchedFiles ( host , additionalFiles ? testProjectExpectedWatchedFiles . concat ( newFile . path ) : testProjectExpectedWatchedFiles ) ;
157
+ checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
158
+ checkWatchedDirectories ( host , [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] , /*recursive*/ true ) ;
159
+ }
160
+ }
161
+
162
+ it ( "change builds changes and reports found errors message" , ( ) => {
163
+ const { host, verifyChangeWithFile, verifyChangeAfterTimeout } = createSolutionInWatchModeToVerifyChanges ( ) ;
164
+ verifyChange ( `${ core [ 1 ] . content }
114
165
export class someClass { }` ) ;
115
166
116
- // Another change requeues and builds it
117
- verifyChange ( core [ 1 ] . content ) ;
167
+ // Another change requeues and builds it
168
+ verifyChange ( core [ 1 ] . content ) ;
118
169
119
- // Two changes together report only single time message: File change detected. Starting incremental compilation...
120
- const outputFileStamps = getOutputFileStamps ( host ) ;
121
- const change1 = `${ core [ 1 ] . content }
170
+ // Two changes together report only single time message: File change detected. Starting incremental compilation...
171
+ const outputFileStamps = getOutputFileStamps ( host ) ;
172
+ const change1 = `${ core [ 1 ] . content }
122
173
export class someClass { }` ;
123
- host . writeFile ( core [ 1 ] . path , change1 ) ;
124
- host . writeFile ( core [ 1 ] . path , `${ change1 }
174
+ host . writeFile ( core [ 1 ] . path , change1 ) ;
175
+ host . writeFile ( core [ 1 ] . path , `${ change1 }
125
176
export class someClass2 { }` ) ;
126
- verifyChangeAfterTimeout ( outputFileStamps ) ;
127
-
128
- function verifyChange ( coreContent : string ) {
129
- const outputFileStamps = getOutputFileStamps ( host ) ;
130
- host . writeFile ( core [ 1 ] . path , coreContent ) ;
131
177
verifyChangeAfterTimeout ( outputFileStamps ) ;
132
- }
133
178
134
- function verifyChangeAfterTimeout ( outputFileStamps : OutputFileStamp [ ] ) {
135
- host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds core
136
- const changedCore = getOutputFileStamps ( host ) ;
137
- verifyChangedFiles ( changedCore , outputFileStamps , [
138
- ...getOutputFileNames ( SubProject . core , "anotherModule" ) , // This should not be written really
139
- ...getOutputFileNames ( SubProject . core , "index" )
140
- ] ) ;
141
- host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds tests
142
- const changedTests = getOutputFileStamps ( host ) ;
143
- verifyChangedFiles ( changedTests , changedCore , [
144
- ...getOutputFileNames ( SubProject . tests , "index" ) // Again these need not be written
145
- ] ) ;
146
- host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Builds logic
147
- const changedLogic = getOutputFileStamps ( host ) ;
148
- verifyChangedFiles ( changedLogic , changedTests , [
149
- ...getOutputFileNames ( SubProject . logic , "index" ) // Again these need not be written
150
- ] ) ;
151
- host . checkTimeoutQueueLength ( 0 ) ;
152
- checkOutputErrorsIncremental ( host , emptyArray ) ;
153
- }
179
+ function verifyChange ( coreContent : string ) {
180
+ verifyChangeWithFile ( core [ 1 ] . path , coreContent ) ;
181
+ }
182
+ } ) ;
183
+
184
+ it ( "builds when new file is added, and its subsequent updates" , ( ) => {
185
+ const additinalFiles : ReadonlyArray < [ SubProject , string ] > = [ [ SubProject . core , newFileWithoutExtension ] ] ;
186
+ const { verifyChangeWithFile } = createSolutionInWatchModeToVerifyChanges ( additinalFiles ) ;
187
+ verifyChange ( newFile . content ) ;
188
+
189
+ // Another change requeues and builds it
190
+ verifyChange ( `${ newFile . content }
191
+ export class someClass2 { }` ) ;
192
+
193
+ function verifyChange ( newFileContent : string ) {
194
+ verifyChangeWithFile ( newFile . path , newFileContent ) ;
195
+ }
196
+ } ) ;
197
+
154
198
} ) ;
155
199
156
200
// TODO: write tests reporting errors but that will have more involved work since file
0 commit comments