@@ -94,6 +94,7 @@ namespace ts.tscWatch {
94
94
const ui = subProjectFiles ( SubProject . ui ) ;
95
95
const allFiles : ReadonlyArray < File > = [ libFile , ...core , ...logic , ...tests , ...ui ] ;
96
96
const testProjectExpectedWatchedFiles = [ core [ 0 ] , core [ 1 ] , core [ 2 ] , ...logic , ...tests ] . map ( f => f . path ) ;
97
+ const testProjectExpectedWatchedDirectoriesRecursive = [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] ;
97
98
98
99
function createSolutionInWatchMode ( allFiles : ReadonlyArray < File > , defaultOptions ?: BuildOptions , disableConsoleClears ?: boolean ) {
99
100
const host = createWatchedSystem ( allFiles , { currentDirectory : projectsLocation } ) ;
@@ -110,7 +111,7 @@ namespace ts.tscWatch {
110
111
function verifyWatches ( host : WatchedSystem ) {
111
112
checkWatchedFiles ( host , testProjectExpectedWatchedFiles ) ;
112
113
checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
113
- checkWatchedDirectories ( host , [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] , /*recursive*/ true ) ;
114
+ checkWatchedDirectories ( host , testProjectExpectedWatchedDirectoriesRecursive , /*recursive*/ true ) ;
114
115
}
115
116
116
117
it ( "creates solution in watch mode" , ( ) => {
@@ -161,7 +162,7 @@ namespace ts.tscWatch {
161
162
function verifyWatches ( ) {
162
163
checkWatchedFiles ( host , additionalFiles ? testProjectExpectedWatchedFiles . concat ( newFile . path ) : testProjectExpectedWatchedFiles ) ;
163
164
checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
164
- checkWatchedDirectories ( host , [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] , /*recursive*/ true ) ;
165
+ checkWatchedDirectories ( host , testProjectExpectedWatchedDirectoriesRecursive , /*recursive*/ true ) ;
165
166
}
166
167
}
167
168
@@ -347,7 +348,7 @@ function myFunc() { return 100; }`);
347
348
function verifyWatches ( ) {
348
349
checkWatchedFiles ( host , projectFiles . map ( f => f . path ) ) ;
349
350
checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
350
- checkWatchedDirectories ( host , [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] , /*recursive*/ true ) ;
351
+ checkWatchedDirectories ( host , testProjectExpectedWatchedDirectoriesRecursive , /*recursive*/ true ) ;
351
352
}
352
353
} ) ;
353
354
@@ -389,12 +390,87 @@ let x: string = 10;`);
389
390
} ) ;
390
391
} ) ;
391
392
392
- it ( "tsc-watch works with project references" , ( ) => {
393
- // Build the composite project
394
- const host = createSolutionInWatchMode ( allFiles ) ;
393
+ describe ( "tsc-watch works with project references" , ( ) => {
394
+ const coreIndexDts = projectFilePath ( SubProject . core , "index.d.ts" ) ;
395
+ const coreAnotherModuleDts = projectFilePath ( SubProject . core , "anotherModule.d.ts" ) ;
396
+ const logicIndexDts = projectFilePath ( SubProject . logic , "index.d.ts" ) ;
397
+ const expectedWatchedFiles = [ core [ 0 ] , logic [ 0 ] , ...tests , libFile ] . map ( f => f . path ) . concat ( coreIndexDts , coreAnotherModuleDts , logicIndexDts ) ;
398
+ const expectedWatchedDirectoriesRecursive = projectSystem . getTypeRootsFromLocation ( projectPath ( SubProject . tests ) ) ;
399
+
400
+ function createSolution ( ) {
401
+ const host = createWatchedSystem ( allFiles , { currentDirectory : projectsLocation } ) ;
402
+ const solutionBuilder = createSolutionBuilder ( host , [ `${ project } /${ SubProject . tests } ` ] , { } ) ;
403
+ return { host, solutionBuilder } ;
404
+ }
395
405
396
- createWatchOfConfigFile ( tests [ 0 ] . path , host ) ;
397
- checkOutputErrorsInitial ( host , emptyArray ) ;
406
+ function createBuiltSolution ( ) {
407
+ const result = createSolution ( ) ;
408
+ const { host, solutionBuilder } = result ;
409
+ solutionBuilder . buildAllProjects ( ) ;
410
+ const outputFileStamps = getOutputFileStamps ( host ) ;
411
+ for ( const stamp of outputFileStamps ) {
412
+ assert . isDefined ( stamp [ 1 ] , `${ stamp [ 0 ] } expected to be present` ) ;
413
+ }
414
+ return result ;
415
+ }
416
+
417
+ function verifyWatches ( host : WatchedSystem ) {
418
+ checkWatchedFilesDetailed ( host , expectedWatchedFiles , 1 ) ;
419
+ checkWatchedDirectories ( host , emptyArray , /*recursive*/ false ) ;
420
+ checkWatchedDirectoriesDetailed ( host , expectedWatchedDirectoriesRecursive , 1 , /*recursive*/ true ) ;
421
+ }
422
+
423
+ function createSolutionAndWatchMode ( ) {
424
+ // Build the composite project
425
+ const { host, solutionBuilder } = createBuiltSolution ( ) ;
426
+
427
+ // Build in watch mode
428
+ const watch = createWatchOfConfigFileReturningBuilder ( tests [ 0 ] . path , host ) ;
429
+ checkOutputErrorsInitial ( host , emptyArray ) ;
430
+
431
+ return { host, solutionBuilder, watch } ;
432
+ }
433
+
434
+ function verifyDependencies ( watch : ( ) => BuilderProgram , filePath : string , expected : ReadonlyArray < string > ) {
435
+ checkArray ( `${ filePath } dependencies` , watch ( ) . getAllDependencies ( watch ( ) . getSourceFile ( filePath ) ! ) . map ( f => f . toLocaleLowerCase ( ) ) , expected ) ;
436
+ }
437
+
438
+ describe ( "invoking when references are already built" , ( ) => {
439
+ it ( "verifies dependencies and watches" , ( ) => {
440
+ const { host, watch } = createSolutionAndWatchMode ( ) ;
441
+
442
+ verifyWatches ( host ) ;
443
+ verifyDependencies ( watch , coreIndexDts , [ coreIndexDts ] ) ;
444
+ verifyDependencies ( watch , coreAnotherModuleDts , [ coreAnotherModuleDts ] ) ;
445
+ verifyDependencies ( watch , logicIndexDts , [ logicIndexDts , coreAnotherModuleDts ] ) ;
446
+ verifyDependencies ( watch , tests [ 1 ] . path , [ tests [ 1 ] . path , coreAnotherModuleDts , logicIndexDts , coreAnotherModuleDts ] ) ;
447
+ } ) ;
448
+
449
+ it ( "local edit in ts file, result in watch compilation because logic.d.ts is written" , ( ) => {
450
+ const { host, solutionBuilder } = createSolutionAndWatchMode ( ) ;
451
+ host . writeFile ( logic [ 1 ] . path , `${ logic [ 1 ] . content }
452
+ function foo() {
453
+ }` ) ;
454
+ solutionBuilder . invalidateProject ( `${ project } /${ SubProject . logic } ` ) ;
455
+ solutionBuilder . buildInvalidatedProject ( ) ;
456
+
457
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ; // not ideal, but currently because of d.ts but no new file is written
458
+ checkOutputErrorsIncremental ( host , emptyArray ) ;
459
+ } ) ;
460
+
461
+ it ( "non local edit in ts file, rebuilds in watch compilation" , ( ) => {
462
+ const { host, solutionBuilder } = createSolutionAndWatchMode ( ) ;
463
+ host . writeFile ( logic [ 1 ] . path , `${ logic [ 1 ] . content }
464
+ export function gfoo() {
465
+ }` ) ;
466
+ solutionBuilder . invalidateProject ( logic [ 0 ] . path ) ;
467
+ solutionBuilder . buildInvalidatedProject ( ) ;
468
+
469
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ;
470
+ checkOutputErrorsIncremental ( host , emptyArray ) ;
471
+ } ) ;
472
+
473
+ } ) ;
398
474
} ) ;
399
475
} ) ;
400
476
}
0 commit comments