@@ -123,4 +123,36 @@ namespace ts.tscWatch {
123123 checkProgramActualFiles ( watch . getProgram ( ) . getProgram ( ) , [ mainFile . path , otherFile . path , libFile . path ] ) ;
124124 } ) ;
125125 } ) ;
126+
127+ describe ( "unittests:: tsc-watch:: watchAPI:: when watchHost uses createSemanticDiagnosticsBuilderProgram" , ( ) => {
128+ it ( "verifies that noEmit is handled on createSemanticDiagnosticsBuilderProgram and typechecking happens only on affected files" , ( ) => {
129+ const config : File = {
130+ path : `${ projectRoot } /tsconfig.json` ,
131+ content : "{}"
132+ } ;
133+ const mainFile : File = {
134+ path : `${ projectRoot } /main.ts` ,
135+ content : "export const x = 10;"
136+ } ;
137+ const otherFile : File = {
138+ path : `${ projectRoot } /other.ts` ,
139+ content : "export const y = 10;"
140+ } ;
141+ const sys = createWatchedSystem ( [ config , mainFile , otherFile , libFile ] ) ;
142+ const watchCompilerHost = createWatchCompilerHost (
143+ config . path ,
144+ { noEmit : true } ,
145+ sys ,
146+ createSemanticDiagnosticsBuilderProgram
147+ ) ;
148+ const watch = createWatchProgram ( watchCompilerHost ) ;
149+ checkProgramActualFiles ( watch . getProgram ( ) . getProgram ( ) , [ mainFile . path , otherFile . path , libFile . path ] ) ;
150+ sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
151+ sys . runQueuedTimeoutCallbacks ( ) ;
152+ const program = watch . getProgram ( ) . getProgram ( ) ;
153+ assert . deepEqual ( program . getCachedSemanticDiagnostics ( program . getSourceFile ( mainFile . path ) ) , [ ] ) ;
154+ // Should not retrieve diagnostics for other file thats not changed
155+ assert . deepEqual ( program . getCachedSemanticDiagnostics ( program . getSourceFile ( otherFile . path ) ) , /*expected*/ undefined ) ;
156+ } ) ;
157+ } ) ;
126158}
0 commit comments