@@ -147,6 +147,21 @@ namespace ts.tscWatch {
147
147
const watch = getWatch ( config , { noEmit : true } , sys , createProgram ) ;
148
148
return { sys, watch, mainFile, otherFile, config } ;
149
149
}
150
+
151
+ function verifyOutputs ( sys : System , emitSys : System ) {
152
+ for ( const output of [ `${ projectRoot } /main.js` , `${ projectRoot } /main.d.ts` , `${ projectRoot } /other.js` , `${ projectRoot } /other.d.ts` , `${ projectRoot } /tsconfig.tsbuildinfo` ] ) {
153
+ assert . strictEqual ( sys . readFile ( output ) , emitSys . readFile ( output ) , `Output file text for ${ output } ` ) ;
154
+ }
155
+ }
156
+
157
+ function verifyBuilder < T extends BuilderProgram , U extends BuilderProgram > ( config : File , sys : System , emitSys : System , createProgram : CreateProgram < T > , createEmitProgram : CreateProgram < U > , optionsToExtend ?: CompilerOptions ) {
158
+ const watch = getWatch ( config , /*optionsToExtend*/ optionsToExtend , sys , createProgram ) ;
159
+ const emitWatch = getWatch ( config , /*optionsToExtend*/ optionsToExtend , emitSys , createEmitProgram ) ;
160
+ verifyOutputs ( sys , emitSys ) ;
161
+ watch . close ( ) ;
162
+ emitWatch . close ( ) ;
163
+ }
164
+
150
165
it ( "verifies that noEmit is handled on createSemanticDiagnosticsBuilderProgram and typechecking happens only on affected files" , ( ) => {
151
166
const { sys, watch, mainFile, otherFile } = setup ( createSemanticDiagnosticsBuilderProgram , "{}" ) ;
152
167
checkProgramActualFiles ( watch . getProgram ( ) . getProgram ( ) , [ mainFile . path , otherFile . path , libFile . path ] ) ;
@@ -168,38 +183,59 @@ namespace ts.tscWatch {
168
183
emitWatch . close ( ) ;
169
184
170
185
// Emit on both sys should result in same output
171
- verifyBuilder ( createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
186
+ verifyBuilder ( config , sys , emitSys , createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
172
187
173
188
// Change file
174
189
sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
175
190
emitSys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
176
191
177
192
// Verify noEmit results in same output
178
- verifyBuilder ( createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmit : true } ) ;
193
+ verifyBuilder ( config , sys , emitSys , createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmit : true } ) ;
179
194
180
195
// Emit on both sys should result in same output
181
- verifyBuilder ( createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
196
+ verifyBuilder ( config , sys , emitSys , createEmitAndSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
182
197
183
198
// Change file
184
199
sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
185
200
emitSys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
186
201
187
202
// Emit on both the builders should result in same files
188
- verifyBuilder ( createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
203
+ verifyBuilder ( config , sys , emitSys , createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram ) ;
204
+ } ) ;
189
205
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
- }
206
+ it ( "noEmitOnError with composite writes the tsbuildinfo with pending affected files correctly" , ( ) => {
207
+ const config : File = {
208
+ path : `${ projectRoot } /tsconfig.json` ,
209
+ content : JSON . stringify ( { compilerOptions : { composite : true } } )
210
+ } ;
211
+ const mainFile : File = {
212
+ path : `${ projectRoot } /main.ts` ,
213
+ content : "export const x: string = 10;"
214
+ } ;
215
+ const otherFile : File = {
216
+ path : `${ projectRoot } /other.ts` ,
217
+ content : "export const y = 10;"
218
+ } ;
219
+ const sys = createWatchedSystem ( [ config , mainFile , otherFile , libFile ] ) ;
220
+ const emitSys = createWatchedSystem ( [ config , mainFile , otherFile , libFile ] ) ;
195
221
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
- }
222
+ // Verify noEmit results in same output
223
+ verifyBuilder ( config , sys , emitSys , createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmitOnError : true } ) ;
224
+
225
+ // Change file
226
+ sys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
227
+ emitSys . appendFile ( mainFile . path , "\n// SomeComment" ) ;
228
+
229
+ // Verify noEmit results in same output
230
+ verifyBuilder ( config , sys , emitSys , createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmitOnError : true } ) ;
231
+
232
+ // Fix error
233
+ const fixed = "export const x = 10;" ;
234
+ sys . appendFile ( mainFile . path , fixed ) ;
235
+ emitSys . appendFile ( mainFile . path , fixed ) ;
236
+
237
+ // Emit on both the builders should result in same files
238
+ verifyBuilder ( config , sys , emitSys , createSemanticDiagnosticsBuilderProgram , createEmitAndSemanticDiagnosticsBuilderProgram , { noEmitOnError : true } ) ;
203
239
} ) ;
204
240
} ) ;
205
241
}
0 commit comments