@@ -113,13 +113,33 @@ namespace ts.tscWatch {
113
113
}
114
114
}
115
115
116
- const core = subProjectFiles ( SubProject . core , /*anotherModuleAndSomeDecl*/ true ) ;
117
- const logic = subProjectFiles ( SubProject . logic ) ;
118
- const tests = subProjectFiles ( SubProject . tests ) ;
119
- const ui = subProjectFiles ( SubProject . ui ) ;
120
- const allFiles : ReadonlyArray < File > = [ libFile , ...core , ...logic , ...tests , ...ui ] ;
121
- const testProjectExpectedWatchedFiles = [ core [ 0 ] , core [ 1 ] , core [ 2 ] ! , ...logic , ...tests ] . map ( f => f . path . toLowerCase ( ) ) ; // tslint:disable-line no-unnecessary-type-assertion (TODO: type assertion should be necessary)
122
- const testProjectExpectedWatchedDirectoriesRecursive = [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] ;
116
+ let core : SubProjectFiles ;
117
+ let logic : SubProjectFiles ;
118
+ let tests : SubProjectFiles ;
119
+ let ui : SubProjectFiles ;
120
+ let allFiles : ReadonlyArray < File > ;
121
+ let testProjectExpectedWatchedFiles : string [ ] ;
122
+ let testProjectExpectedWatchedDirectoriesRecursive : string [ ] ;
123
+
124
+ before ( ( ) => {
125
+ core = subProjectFiles ( SubProject . core , /*anotherModuleAndSomeDecl*/ true ) ;
126
+ logic = subProjectFiles ( SubProject . logic ) ;
127
+ tests = subProjectFiles ( SubProject . tests ) ;
128
+ ui = subProjectFiles ( SubProject . ui ) ;
129
+ allFiles = [ libFile , ...core , ...logic , ...tests , ...ui ] ;
130
+ testProjectExpectedWatchedFiles = [ core [ 0 ] , core [ 1 ] , core [ 2 ] ! , ...logic , ...tests ] . map ( f => f . path . toLowerCase ( ) ) ; // tslint:disable-line no-unnecessary-type-assertion (TODO: type assertion should be necessary)
131
+ testProjectExpectedWatchedDirectoriesRecursive = [ projectPath ( SubProject . core ) , projectPath ( SubProject . logic ) ] ;
132
+ } ) ;
133
+
134
+ after ( ( ) => {
135
+ core = undefined ! ;
136
+ logic = undefined ! ;
137
+ tests = undefined ! ;
138
+ ui = undefined ! ;
139
+ allFiles = undefined ! ;
140
+ testProjectExpectedWatchedFiles = undefined ! ;
141
+ testProjectExpectedWatchedDirectoriesRecursive = undefined ! ;
142
+ } ) ;
123
143
124
144
function createSolutionInWatchMode ( allFiles : ReadonlyArray < File > , defaultOptions ?: BuildOptions , disableConsoleClears ?: boolean ) {
125
145
const host = createTsBuildWatchSystem ( allFiles , { currentDirectory : projectsLocation } ) ;
@@ -172,9 +192,9 @@ namespace ts.tscWatch {
172
192
content : `export const newFileConst = 30;`
173
193
} ;
174
194
175
- function verifyProjectChanges ( allFiles : ReadonlyArray < File > ) {
195
+ function verifyProjectChanges ( allFilesGetter : ( ) => ReadonlyArray < File > ) {
176
196
function createSolutionInWatchModeToVerifyChanges ( additionalFiles ?: ReadonlyArray < [ SubProject , string ] > ) {
177
- const host = createSolutionInWatchMode ( allFiles ) ;
197
+ const host = createSolutionInWatchMode ( allFilesGetter ( ) ) ;
178
198
return { host, verifyChangeWithFile, verifyChangeAfterTimeout, verifyWatches } ;
179
199
180
200
function verifyChangeWithFile ( fileName : string , content : string , local ?: boolean ) {
@@ -277,19 +297,21 @@ export class someClass2 { }`);
277
297
}
278
298
279
299
describe ( "with simple project reference graph" , ( ) => {
280
- verifyProjectChanges ( allFiles ) ;
300
+ verifyProjectChanges ( ( ) => allFiles ) ;
281
301
} ) ;
282
302
283
303
describe ( "with circular project reference" , ( ) => {
284
- const [ coreTsconfig , ...otherCoreFiles ] = core ;
285
- const circularCoreConfig : File = {
286
- path : coreTsconfig . path ,
287
- content : JSON . stringify ( {
288
- compilerOptions : { composite : true , declaration : true } ,
289
- references : [ { path : "../tests" , circular : true } ]
290
- } )
291
- } ;
292
- verifyProjectChanges ( [ libFile , circularCoreConfig , ...otherCoreFiles , ...logic , ...tests ] ) ;
304
+ verifyProjectChanges ( ( ) => {
305
+ const [ coreTsconfig , ...otherCoreFiles ] = core ;
306
+ const circularCoreConfig : File = {
307
+ path : coreTsconfig . path ,
308
+ content : JSON . stringify ( {
309
+ compilerOptions : { composite : true , declaration : true } ,
310
+ references : [ { path : "../tests" , circular : true } ]
311
+ } )
312
+ } ;
313
+ return [ libFile , circularCoreConfig , ...otherCoreFiles , ...logic , ...tests ] ;
314
+ } ) ;
293
315
} ) ;
294
316
} ) ;
295
317
@@ -681,9 +703,9 @@ let x: string = 10;`);
681
703
const coreIndexDts = projectFileName ( SubProject . core , "index.d.ts" ) ;
682
704
const coreAnotherModuleDts = projectFileName ( SubProject . core , "anotherModule.d.ts" ) ;
683
705
const logicIndexDts = projectFileName ( SubProject . logic , "index.d.ts" ) ;
684
- const expectedWatchedFiles = [ core [ 0 ] , logic [ 0 ] , ...tests , libFile ] . map ( f => f . path ) . concat ( [ coreIndexDts , coreAnotherModuleDts , logicIndexDts ] . map ( f => f . toLowerCase ( ) ) ) ;
706
+ const expectedWatchedFiles = ( ) => [ core [ 0 ] , logic [ 0 ] , ...tests , libFile ] . map ( f => f . path ) . concat ( [ coreIndexDts , coreAnotherModuleDts , logicIndexDts ] . map ( f => f . toLowerCase ( ) ) ) ;
685
707
const expectedWatchedDirectoriesRecursive = projectSystem . getTypeRootsFromLocation ( projectPath ( SubProject . tests ) ) ;
686
- const expectedProgramFiles = [ tests [ 1 ] . path , libFile . path , coreIndexDts , coreAnotherModuleDts , logicIndexDts ] ;
708
+ const expectedProgramFiles = ( ) => [ tests [ 1 ] . path , libFile . path , coreIndexDts , coreAnotherModuleDts , logicIndexDts ] ;
687
709
688
710
function createSolutionAndWatchMode ( ) {
689
711
return createSolutionAndWatchModeOfProject ( allFiles , projectsLocation , `${ project } /${ SubProject . tests } ` , tests [ 0 ] . path , getOutputFileStamps ) ;
@@ -694,12 +716,12 @@ let x: string = 10;`);
694
716
}
695
717
696
718
function verifyWatches ( host : TsBuildWatchSystem , withTsserver ?: boolean ) {
697
- verifyWatchesOfProject ( host , withTsserver ? expectedWatchedFiles . filter ( f => f !== tests [ 1 ] . path . toLowerCase ( ) ) : expectedWatchedFiles , expectedWatchedDirectoriesRecursive ) ;
719
+ verifyWatchesOfProject ( host , withTsserver ? expectedWatchedFiles ( ) . filter ( f => f !== tests [ 1 ] . path . toLowerCase ( ) ) : expectedWatchedFiles ( ) , expectedWatchedDirectoriesRecursive ) ;
698
720
}
699
721
700
722
function verifyScenario (
701
723
edit : ( host : TsBuildWatchSystem , solutionBuilder : SolutionBuilder < EmitAndSemanticDiagnosticsBuilderProgram > ) => void ,
702
- expectedFilesAfterEdit : ReadonlyArray < string >
724
+ expectedFilesAfterEdit : ( ) => ReadonlyArray < string >
703
725
) {
704
726
it ( "with tsc-watch" , ( ) => {
705
727
const { host, solutionBuilder, watch } = createSolutionAndWatchMode ( ) ;
@@ -708,7 +730,7 @@ let x: string = 10;`);
708
730
709
731
host . checkTimeoutQueueLengthAndRun ( 1 ) ;
710
732
checkOutputErrorsIncremental ( host , emptyArray ) ;
711
- checkProgramActualFiles ( watch ( ) , expectedFilesAfterEdit ) ;
733
+ checkProgramActualFiles ( watch ( ) , expectedFilesAfterEdit ( ) ) ;
712
734
713
735
} ) ;
714
736
@@ -718,7 +740,7 @@ let x: string = 10;`);
718
740
edit ( host , solutionBuilder ) ;
719
741
720
742
host . checkTimeoutQueueLengthAndRun ( 2 ) ;
721
- checkProjectActualFiles ( service , tests [ 0 ] . path , [ tests [ 0 ] . path , ...expectedFilesAfterEdit ] ) ;
743
+ checkProjectActualFiles ( service , tests [ 0 ] . path , [ tests [ 0 ] . path , ...expectedFilesAfterEdit ( ) ] ) ;
722
744
} ) ;
723
745
}
724
746
@@ -729,7 +751,7 @@ let x: string = 10;`);
729
751
verifyDependencies ( watch , coreIndexDts , [ coreIndexDts ] ) ;
730
752
verifyDependencies ( watch , coreAnotherModuleDts , [ coreAnotherModuleDts ] ) ;
731
753
verifyDependencies ( watch , logicIndexDts , [ logicIndexDts , coreAnotherModuleDts ] ) ;
732
- verifyDependencies ( watch , tests [ 1 ] . path , expectedProgramFiles . filter ( f => f !== libFile . path ) ) ;
754
+ verifyDependencies ( watch , tests [ 1 ] . path , expectedProgramFiles ( ) . filter ( f => f !== libFile . path ) ) ;
733
755
} ) ;
734
756
735
757
it ( "with tsserver" , ( ) => {
@@ -769,7 +791,7 @@ export function gfoo() {
769
791
} ) ) ;
770
792
solutionBuilder . invalidateProject ( logic [ 0 ] . path . toLowerCase ( ) as ResolvedConfigFilePath , ConfigFileProgramReloadLevel . Full ) ;
771
793
solutionBuilder . buildNextInvalidatedProject ( ) ;
772
- } , [ tests [ 1 ] . path , libFile . path , coreIndexDts , coreAnotherModuleDts , projectFilePath ( SubProject . logic , "decls/index.d.ts" ) ] ) ;
794
+ } , ( ) => [ tests [ 1 ] . path , libFile . path , coreIndexDts , coreAnotherModuleDts , projectFilePath ( SubProject . logic , "decls/index.d.ts" ) ] ) ;
773
795
} ) ;
774
796
} ) ;
775
797
0 commit comments