@@ -125,10 +125,15 @@ namespace ts.tscWatch {
125
125
} ) ;
126
126
127
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" , ( ) => {
128
+ function getWatch < T extends BuilderProgram > ( config : File , optionsToExtend : CompilerOptions | undefined , sys : System , createProgram : CreateProgram < T > ) {
129
+ const watchCompilerHost = createWatchCompilerHost ( config . path , optionsToExtend , sys , createProgram ) ;
130
+ return createWatchProgram ( watchCompilerHost ) ;
131
+ }
132
+
133
+ function setup < T extends BuilderProgram > ( createProgram : CreateProgram < T > , configText : string ) {
129
134
const config : File = {
130
135
path : `${ projectRoot } /tsconfig.json` ,
131
- content : "{}"
136
+ content : configText
132
137
} ;
133
138
const mainFile : File = {
134
139
path : `${ projectRoot } /main.ts` ,
@@ -139,13 +144,11 @@ namespace ts.tscWatch {
139
144
content : "export const y = 10;"
140
145
} ;
141
146
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 ) ;
147
+ const watch = getWatch ( config , { noEmit : true } , sys , createProgram ) ;
148
+ return { sys, watch, mainFile, otherFile, config } ;
149
+ }
150
+ it ( "verifies that noEmit is handled on createSemanticDiagnosticsBuilderProgram and typechecking happens only on affected files" , ( ) => {
151
+ const { sys, watch, mainFile, otherFile } = setup ( createSemanticDiagnosticsBuilderProgram , "{}" ) ;
149
152
checkProgramActualFiles ( watch . getProgram ( ) . getProgram ( ) , [ mainFile . path , otherFile . path , libFile . path ] ) ;
150
153
sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
151
154
sys . runQueuedTimeoutCallbacks ( ) ;
@@ -154,5 +157,49 @@ namespace ts.tscWatch {
154
157
// Should not retrieve diagnostics for other file thats not changed
155
158
assert . deepEqual ( program . getCachedSemanticDiagnostics ( program . getSourceFile ( otherFile . path ) ) , /*expected*/ undefined ) ;
156
159
} ) ;
160
+
161
+ it ( "noEmit with composite writes the tsbuildinfo with pending affected files correctly" , ( ) => {
162
+ const configText = JSON . stringify ( { compilerOptions : { composite : true } } ) ;
163
+ const { sys, watch, config, mainFile } = setup ( createSemanticDiagnosticsBuilderProgram , configText ) ;
164
+ const { sys : emitSys , watch : emitWatch } = setup ( createEmitAndSemanticDiagnosticsBuilderProgram , configText ) ;
165
+ verifyOutputs ( sys , emitSys ) ;
166
+
167
+ watch . close ( ) ;
168
+ emitWatch . close ( ) ;
169
+
170
+ // Emit on both sys should result in same output
171
+ verifyBuilder ( createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
172
+
173
+ // Change file
174
+ sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
175
+ emitSys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
176
+
177
+ // Verify noEmit results in same output
178
+ verifyBuilder ( createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmit : true } ) ;
179
+
180
+ // Emit on both sys should result in same output
181
+ verifyBuilder ( createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
182
+
183
+ // Change file
184
+ sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
185
+ emitSys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
186
+
187
+ // Emit on both the builders should result in same files
188
+ verifyBuilder ( createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
189
+
190
+ function verifyOutputs ( sys : System , emitSys : System ) {
191
+ for ( const output of [ `${ projectRoot } /main.js` , `${ projectRoot } /main.d.ts` , `${ projectRoot } /other.js` , `${ projectRoot } /other.d.ts` , `${ projectRoot } /tsconfig.tsbuildinfo` ] ) {
192
+ assert . strictEqual ( sys . readFile ( output ) , emitSys . readFile ( output ) , `Output file text for ${ output } ` ) ;
193
+ }
194
+ }
195
+
196
+ function verifyBuilder < T extends BuilderProgram , U extends BuilderProgram > ( createProgram : CreateProgram < T > , createEmitProgram : CreateProgram < U > , optionsToExtend ?: CompilerOptions ) {
197
+ const watch = getWatch ( config , /*optionsToExtend*/ optionsToExtend , sys , createProgram ) ;
198
+ const emitWatch = getWatch ( config , /*optionsToExtend*/ optionsToExtend , emitSys , createEmitProgram ) ;
199
+ verifyOutputs ( sys , emitSys ) ;
200
+ watch . close ( ) ;
201
+ emitWatch . close ( ) ;
202
+ }
203
+ } ) ;
157
204
} ) ;
158
205
}
0 commit comments