@@ -2176,49 +2176,64 @@ declare module "fs" {
21762176 }
21772177 } ) ;
21782178
2179- it ( "watchingDirectories with watchFile" , ( ) => {
2180- const projectFolder = "/a/username/project" ;
2181- const projectSrcFolder = `${ projectFolder } /src` ;
2182- const configFile : FileOrFolder = {
2183- path : `${ projectFolder } /tsconfig.json` ,
2184- content : "{}"
2185- } ;
2186- const file : FileOrFolder = {
2187- path : `${ projectSrcFolder } /file1.ts` ,
2188- content : ""
2189- } ;
2190- const programFiles = [ file , libFile ] ;
2191- const files = [ file , configFile , libFile ] ;
2192- const environmentVariables = createMap < string > ( ) ;
2193- environmentVariables . set ( "TSC_WATCHDIRECTORY" , "RecursiveDirectoryUsingFsWatchFile" ) ;
2194- const host = createWatchedSystem ( files , { environmentVariables } ) ;
2195- const watch = createWatchModeWithConfigFile ( configFile . path , host ) ;
2196- // Watching config file, file, lib file and directories
2197- const expectedWatchedFiles = files . map ( f => f . path ) . concat ( projectFolder , projectSrcFolder , `${ projectFolder } /node_modules/@types` ) ;
2179+ describe ( "tsc-watch when watchDirectories implementation" , ( ) => {
2180+ function verifyRenamingFileInSubFolder ( usesWatchFile : boolean ) {
2181+ const projectFolder = "/a/username/project" ;
2182+ const projectSrcFolder = `${ projectFolder } /src` ;
2183+ const configFile : FileOrFolder = {
2184+ path : `${ projectFolder } /tsconfig.json` ,
2185+ content : "{}"
2186+ } ;
2187+ const file : FileOrFolder = {
2188+ path : `${ projectSrcFolder } /file1.ts` ,
2189+ content : ""
2190+ } ;
2191+ const programFiles = [ file , libFile ] ;
2192+ const files = [ file , configFile , libFile ] ;
2193+ const environmentVariables = createMap < string > ( ) ;
2194+ environmentVariables . set ( "TSC_WATCHDIRECTORY" , usesWatchFile ? "RecursiveDirectoryUsingFsWatchFile" : "RecursiveDirectoryUsingNonRecursiveWatchDirectory" ) ;
2195+ const host = createWatchedSystem ( files , { environmentVariables } ) ;
2196+ const watch = createWatchModeWithConfigFile ( configFile . path , host ) ;
2197+ const projectFolders = [ projectFolder , projectSrcFolder , `${ projectFolder } /node_modules/@types` ] ;
2198+ // Watching files config file, file, lib file
2199+ const expectedWatchedFiles = files . map ( f => f . path ) ;
2200+ const expectedWatchedDirectories = usesWatchFile ? [ ] : projectFolders ;
2201+ if ( usesWatchFile ) {
2202+ expectedWatchedFiles . push ( ...projectFolders ) ;
2203+ }
21982204
2199- verifyProgram ( checkOutputErrorsInitial ) ;
2205+ verifyProgram ( checkOutputErrorsInitial ) ;
22002206
2201- // Rename the file:
2202- file . path = file . path . replace ( "file1.ts" , "file2.ts" ) ;
2203- expectedWatchedFiles [ 0 ] = file . path ;
2204- host . reloadFS ( files ) ;
2205- host . runQueuedTimeoutCallbacks ( ) ;
2206- verifyProgram ( checkOutputErrorsIncremental ) ;
2207+ // Rename the file:
2208+ file . path = file . path . replace ( "file1.ts" , "file2.ts" ) ;
2209+ expectedWatchedFiles [ 0 ] = file . path ;
2210+ host . reloadFS ( files ) ;
2211+ host . runQueuedTimeoutCallbacks ( ) ;
2212+ verifyProgram ( checkOutputErrorsIncremental ) ;
22072213
2208- function verifyProgram ( checkOutputErrors : ( host : WatchedSystem , errors : ReadonlyArray < Diagnostic > ) => void ) {
2209- checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
2210- checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
2214+ function verifyProgram ( checkOutputErrors : ( host : WatchedSystem , errors : ReadonlyArray < Diagnostic > ) => void ) {
2215+ checkWatchedDirectories ( host , emptyArray , /*recursive*/ true ) ;
22112216
2212- // Watching config file, file, lib file and directories
2213- ts . TestFSWithWatch . checkMultiMapEachKeyWithCount ( "watchedFiles" , host . watchedFiles , expectedWatchedFiles , 1 ) ;
2217+ // Watching config file, file, lib file and directories
2218+ ts . TestFSWithWatch . checkMultiMapEachKeyWithCount ( "watchedFiles" , host . watchedFiles , expectedWatchedFiles , 1 ) ;
2219+ ts . TestFSWithWatch . checkMultiMapEachKeyWithCount ( "watchedDirectories" , host . watchedDirectories , expectedWatchedDirectories , 1 ) ;
22142220
2215- checkProgramActualFiles ( watch ( ) , programFiles . map ( f => f . path ) ) ;
2216- checkOutputErrors ( host , emptyArray ) ;
2221+ checkProgramActualFiles ( watch ( ) , programFiles . map ( f => f . path ) ) ;
2222+ checkOutputErrors ( host , emptyArray ) ;
22172223
2218- const outputFile = changeExtension ( file . path , ".js" ) ;
2219- assert ( host . fileExists ( outputFile ) ) ;
2220- assert . equal ( host . readFile ( outputFile ) , file . content ) ;
2224+ const outputFile = changeExtension ( file . path , ".js" ) ;
2225+ assert ( host . fileExists ( outputFile ) ) ;
2226+ assert . equal ( host . readFile ( outputFile ) , file . content ) ;
2227+ }
22212228 }
2229+
2230+ it ( "uses watchFile when renaming file in subfolder" , ( ) => {
2231+ verifyRenamingFileInSubFolder ( /*usesWatchFile*/ true ) ;
2232+ } ) ;
2233+
2234+ it ( "uses non recursive watchDirectory when renaming file in subfolder" , ( ) => {
2235+ verifyRenamingFileInSubFolder ( /*usesWatchFile*/ false ) ;
2236+ } ) ;
22222237 } ) ;
22232238 } ) ;
22242239}
0 commit comments