@@ -269,11 +269,12 @@ interface Symbol {
269
269
tick : ( ) => void ;
270
270
baseFs : vfs . FileSystem ;
271
271
newSys : TscCompileSystem ;
272
+ cleanBuildDescripencies : TscIncremental [ "cleanBuildDescripencies" ] ;
272
273
}
273
274
function verifyIncrementalCorrectness ( input : ( ) => VerifyIncrementalCorrectness , index : number ) {
274
275
it ( `Verify emit output file text is same when built clean for incremental scenario at:: ${ index } ` , ( ) => {
275
276
const {
276
- scenario, subScenario, commandLineArgs,
277
+ scenario, subScenario, commandLineArgs, cleanBuildDescripencies ,
277
278
modifyFs, incrementalModifyFs,
278
279
tick, baseFs, newSys
279
280
} = input ( ) ;
@@ -288,54 +289,82 @@ interface Symbol {
288
289
incrementalModifyFs ( fs ) ;
289
290
} ,
290
291
} ) ;
292
+ const descripencies = cleanBuildDescripencies ?.( ) ;
291
293
for ( const outputFile of arrayFrom ( sys . writtenFiles . keys ( ) ) ) {
292
- const expectedText = sys . readFile ( outputFile ) ;
293
- const actualText = newSys . readFile ( outputFile ) ;
294
+ const cleanBuildText = sys . readFile ( outputFile ) ;
295
+ const incrementalBuildText = newSys . readFile ( outputFile ) ;
296
+ const descripencyInClean = descripencies ?. get ( outputFile ) ;
294
297
if ( ! isBuildInfoFile ( outputFile ) ) {
295
- assert . equal ( actualText , expectedText , `File: ${ outputFile } ` ) ;
298
+ verifyTextEqual ( incrementalBuildText , cleanBuildText , descripencyInClean , `File: ${ outputFile } ` ) ;
296
299
}
297
- else if ( actualText !== expectedText ) {
300
+ else if ( incrementalBuildText !== cleanBuildText ) {
298
301
// Verify build info without affectedFilesPendingEmit
299
- const { buildInfo : actualBuildInfo , affectedFilesPendingEmit : actualAffectedFilesPendingEmit } = getBuildInfoForIncrementalCorrectnessCheck ( actualText ) ;
300
- const { buildInfo : expectedBuildInfo , affectedFilesPendingEmit : expectedAffectedFilesPendingEmit } = getBuildInfoForIncrementalCorrectnessCheck ( expectedText ) ;
301
- assert . deepEqual ( actualBuildInfo , expectedBuildInfo , `TsBuild info text without affectedFilesPendingEmit: ${ outputFile } ::\nIncremental buildInfoText:: ${ actualText } \nClean buildInfoText:: ${ expectedText } ` ) ;
302
+ const { buildInfo : incrementalBuildInfo , affectedFilesPendingEmit : incrementalBuildAffectedFilesPendingEmit } = getBuildInfoForIncrementalCorrectnessCheck ( incrementalBuildText ) ;
303
+ const { buildInfo : cleanBuildInfo , affectedFilesPendingEmit : incrementalAffectedFilesPendingEmit } = getBuildInfoForIncrementalCorrectnessCheck ( cleanBuildText ) ;
304
+ verifyTextEqual ( incrementalBuildInfo , cleanBuildInfo , descripencyInClean , `TsBuild info text without affectedFilesPendingEmit ${ subScenario } :: ${ outputFile } ::\nIncremental buildInfoText:: ${ incrementalBuildText } \nClean buildInfoText:: ${ cleanBuildText } ` ) ;
302
305
// Verify that incrementally pending affected file emit are in clean build since clean build can contain more files compared to incremental depending of noEmitOnError option
303
- if ( actualAffectedFilesPendingEmit ) {
304
- assert . isDefined ( expectedAffectedFilesPendingEmit , `Incremental build contains affectedFilesPendingEmit, clean build should also have it: ${ outputFile } ::\nIncremental buildInfoText:: ${ actualText } \nClean buildInfoText:: ${ expectedText } ` ) ;
306
+ if ( incrementalBuildAffectedFilesPendingEmit && descripencyInClean === undefined ) {
307
+ assert . isDefined ( incrementalAffectedFilesPendingEmit , `Incremental build contains affectedFilesPendingEmit, clean build should also have it: ${ outputFile } ::\nIncremental buildInfoText:: ${ incrementalBuildText } \nClean buildInfoText:: ${ cleanBuildText } ` ) ;
305
308
let expectedIndex = 0 ;
306
- actualAffectedFilesPendingEmit . forEach ( ( [ actualFile ] ) => {
307
- expectedIndex = findIndex ( expectedAffectedFilesPendingEmit ! , ( [ expectedFile ] ) => actualFile === expectedFile , expectedIndex ) ;
308
- assert . notEqual ( expectedIndex , - 1 , `Incremental build contains ${ actualFile } file as pending emit, clean build should also have it: ${ outputFile } ::\nIncremental buildInfoText:: ${ actualText } \nClean buildInfoText:: ${ expectedText } ` ) ;
309
+ incrementalBuildAffectedFilesPendingEmit . forEach ( ( [ actualFile ] ) => {
310
+ expectedIndex = findIndex ( incrementalAffectedFilesPendingEmit ! , ( [ expectedFile ] ) => actualFile === expectedFile , expectedIndex ) ;
311
+ assert . notEqual ( expectedIndex , - 1 , `Incremental build contains ${ actualFile } file as pending emit, clean build should also have it: ${ outputFile } ::\nIncremental buildInfoText:: ${ incrementalBuildText } \nClean buildInfoText:: ${ cleanBuildText } ` ) ;
309
312
expectedIndex ++ ;
310
313
} ) ;
311
314
}
312
315
}
313
316
}
317
+
318
+ function verifyTextEqual ( incrementalText : string | undefined , cleanText : string | undefined , descripencyInClean : CleanBuildDescripency | undefined , message : string ) {
319
+ if ( descripencyInClean === undefined ) {
320
+ assert . equal ( incrementalText , cleanText , message ) ;
321
+ return ;
322
+ }
323
+ switch ( descripencyInClean ) {
324
+ case CleanBuildDescripency . CleanFileTextDifferent :
325
+ assert . isDefined ( incrementalText , `Incremental file should be present:: ${ message } ` ) ;
326
+ assert . isDefined ( cleanText , `Clean file should be present present:: ${ message } ` ) ;
327
+ assert . notEqual ( incrementalText , cleanText , message ) ;
328
+ return ;
329
+ case CleanBuildDescripency . CleanFilePresent :
330
+ assert . isUndefined ( incrementalText , `Incremental file should be absent:: ${ message } ` ) ;
331
+ assert . isDefined ( cleanText , `Clean file should be present:: ${ message } ` ) ;
332
+ return ;
333
+ default :
334
+ Debug . assertNever ( descripencyInClean ) ;
335
+ }
336
+ }
314
337
} ) ;
315
338
}
316
339
317
- function getBuildInfoForIncrementalCorrectnessCheck ( text : string | undefined ) : { buildInfo : BuildInfo | undefined ; affectedFilesPendingEmit ?: ProgramBuildInfo [ "affectedFilesPendingEmit" ] ; } {
340
+ function getBuildInfoForIncrementalCorrectnessCheck ( text : string | undefined ) : { buildInfo : string | undefined ; affectedFilesPendingEmit ?: ProgramBuildInfo [ "affectedFilesPendingEmit" ] ; } {
318
341
const buildInfo = text ? getBuildInfo ( text ) : undefined ;
319
- if ( ! buildInfo ?. program ) return { buildInfo } ;
342
+ if ( ! buildInfo ?. program ) return { buildInfo : text } ;
320
343
// Ignore noEmit since that shouldnt be reason to emit the tsbuild info and presence of it in the buildinfo file does not matter
321
344
const { program : { affectedFilesPendingEmit, options : { noEmit, ...optionsRest } , ...programRest } , ...rest } = buildInfo ;
322
345
return {
323
- buildInfo : {
346
+ buildInfo : getBuildInfoText ( {
324
347
...rest ,
325
348
program : {
326
349
options : optionsRest ,
327
350
...programRest
328
351
}
329
- } ,
352
+ } ) ,
330
353
affectedFilesPendingEmit
331
354
} ;
332
355
}
333
356
357
+ export enum CleanBuildDescripency {
358
+ CleanFileTextDifferent ,
359
+ CleanFilePresent ,
360
+ }
361
+
334
362
export interface TscIncremental {
335
363
buildKind : BuildKind ;
336
364
modifyFs : ( fs : vfs . FileSystem ) => void ;
337
365
subScenario ?: string ;
338
366
commandLineArgs ?: readonly string [ ] ;
367
+ cleanBuildDescripencies ?: ( ) => ESMap < string , CleanBuildDescripency > ;
339
368
}
340
369
341
370
export interface VerifyTsBuildInput extends VerifyTsBuildInputWorker {
@@ -395,7 +424,8 @@ interface Symbol {
395
424
buildKind,
396
425
modifyFs : incrementalModifyFs ,
397
426
subScenario : incrementalSubScenario ,
398
- commandLineArgs : incrementalCommandLineArgs
427
+ commandLineArgs : incrementalCommandLineArgs ,
428
+ cleanBuildDescripencies,
399
429
} , index ) => {
400
430
describe ( incrementalSubScenario || buildKind , ( ) => {
401
431
let newSys : TscCompileSystem ;
@@ -424,10 +454,11 @@ interface Symbol {
424
454
verifyTscBaseline ( ( ) => newSys ) ;
425
455
verifyIncrementalCorrectness ( ( ) => ( {
426
456
scenario,
427
- subScenario,
457
+ subScenario : incrementalSubScenario || subScenario ,
428
458
baseFs,
429
459
newSys,
430
460
commandLineArgs : incrementalCommandLineArgs || commandLineArgs ,
461
+ cleanBuildDescripencies,
431
462
incrementalModifyFs,
432
463
modifyFs,
433
464
tick
@@ -519,12 +550,13 @@ interface Symbol {
519
550
} ) ) ;
520
551
} ) ;
521
552
describe ( "incremental correctness" , ( ) => {
522
- incrementalScenarios . forEach ( ( { commandLineArgs : incrementalCommandLineArgs } , index ) => verifyIncrementalCorrectness ( ( ) => ( {
553
+ incrementalScenarios . forEach ( ( { commandLineArgs : incrementalCommandLineArgs , subScenario , buildKind , cleanBuildDescripencies } , index ) => verifyIncrementalCorrectness ( ( ) => ( {
523
554
scenario,
524
- subScenario,
555
+ subScenario : subScenario || buildKind ,
525
556
baseFs,
526
557
newSys : incrementalSys [ index ] ,
527
558
commandLineArgs : incrementalCommandLineArgs || commandLineArgs ,
559
+ cleanBuildDescripencies,
528
560
incrementalModifyFs : fs => {
529
561
for ( let i = 0 ; i <= index ; i ++ ) {
530
562
incrementalScenarios [ i ] . modifyFs ( fs ) ;
0 commit comments