@@ -479,6 +479,113 @@ let x: string = 10;`);
479
479
it ( "when preserveWatchOutput is passed on command line" , ( ) => {
480
480
verifyIncrementalErrors ( { preserveWatchOutput : true , watch : true } , /*disabledConsoleClear*/ true ) ;
481
481
} ) ;
482
+
483
+ describe ( "when declaration emit errors are present" , ( ) => {
484
+ const solution = "solution" ;
485
+ const subProject = "app" ;
486
+ const subProjectLocation = `${ projectsLocation } /${ solution } /${ subProject } ` ;
487
+ const fileWithError : File = {
488
+ path : `${ subProjectLocation } /fileWithError.ts` ,
489
+ content : `export var myClassWithError = class {
490
+ tags() { }
491
+ private p = 12
492
+ };`
493
+ } ;
494
+ const fileWithFixedError : File = {
495
+ path : fileWithError . path ,
496
+ content : fileWithError . content . replace ( "private p = 12" , "" )
497
+ } ;
498
+ const fileWithoutError : File = {
499
+ path : `${ subProjectLocation } /fileWithoutError.ts` ,
500
+ content : `export class myClass { }`
501
+ } ;
502
+ const tsconfig : File = {
503
+ path : `${ subProjectLocation } /tsconfig.json` ,
504
+ content : JSON . stringify ( { compilerOptions : { composite : true } } )
505
+ } ;
506
+ const expectedDtsEmitErrors = [
507
+ `${ subProject } /fileWithError.ts(1,12): error TS4094: Property 'p' of exported class expression may not be private or protected.\n`
508
+ ] ;
509
+ const outputs = [
510
+ changeExtension ( fileWithError . path , Extension . Js ) ,
511
+ changeExtension ( fileWithError . path , Extension . Dts ) ,
512
+ changeExtension ( fileWithoutError . path , Extension . Js ) ,
513
+ changeExtension ( fileWithoutError . path , Extension . Dts )
514
+ ] ;
515
+
516
+ function verifyDtsErrors ( host : TsBuildWatchSystem , isIncremental : boolean , expectedErrors : ReadonlyArray < string > ) {
517
+ ( isIncremental ? checkOutputErrorsIncremental : checkOutputErrorsInitial ) ( host , expectedErrors ) ;
518
+ outputs . forEach ( f => assert . equal ( host . fileExists ( f ) , ! expectedErrors . length , `Expected file ${ f } to ${ ! expectedErrors . length ? "exist" : "not exist" } ` ) ) ;
519
+ }
520
+
521
+ function createSolutionWithWatch ( withFixedError ?: true ) {
522
+ const files = [ libFile , withFixedError ? fileWithFixedError : fileWithError , fileWithoutError , tsconfig ] ;
523
+ const host = createTsBuildWatchSystem ( files , { currentDirectory : `${ projectsLocation } /${ solution } ` } ) ;
524
+ createSolutionBuilderWithWatch ( host , [ subProject ] ) ;
525
+ verifyDtsErrors ( host , /*isIncremental*/ false , withFixedError ? emptyArray : expectedDtsEmitErrors ) ;
526
+ return host ;
527
+ }
528
+
529
+ function incrementalBuild ( host : TsBuildWatchSystem ) {
530
+ host . checkTimeoutQueueLengthAndRun ( 1 ) ; // Build the app
531
+ host . checkTimeoutQueueLength ( 0 ) ;
532
+ }
533
+
534
+ function fixError ( host : TsBuildWatchSystem ) {
535
+ // Fix error
536
+ host . writeFile ( fileWithError . path , fileWithFixedError . content ) ;
537
+ host . writtenFiles . clear ( ) ;
538
+ incrementalBuild ( host ) ;
539
+ verifyDtsErrors ( host , /*isIncremental*/ true , emptyArray ) ;
540
+ }
541
+
542
+ it ( "when fixing error files all files are emitted" , ( ) => {
543
+ const host = createSolutionWithWatch ( ) ;
544
+ fixError ( host ) ;
545
+ } ) ;
546
+
547
+ it ( "when file with no error changes, declaration errors are reported" , ( ) => {
548
+ const host = createSolutionWithWatch ( ) ;
549
+ host . writeFile ( fileWithoutError . path , fileWithoutError . content . replace ( / m y C l a s s / g, "myClass2" ) ) ;
550
+ incrementalBuild ( host ) ;
551
+ verifyDtsErrors ( host , /*isIncremental*/ true , expectedDtsEmitErrors ) ;
552
+ } ) ;
553
+
554
+ describe ( "when reporting errors on introducing error" , ( ) => {
555
+ function createSolutionWithIncrementalError ( ) {
556
+ const host = createSolutionWithWatch ( /*withFixedError*/ true ) ;
557
+ host . writeFile ( fileWithError . path , fileWithError . content ) ;
558
+ host . writtenFiles . clear ( ) ;
559
+
560
+ incrementalBuild ( host ) ;
561
+ checkOutputErrorsIncremental ( host , expectedDtsEmitErrors ) ;
562
+ assert . equal ( host . writtenFiles . size , 0 , `Expected not to write any files: ${ arrayFrom ( host . writtenFiles . keys ( ) ) } ` ) ;
563
+ return host ;
564
+ }
565
+
566
+ function verifyWrittenFile ( host : TsBuildWatchSystem , f : string ) {
567
+ assert . isTrue ( host . writtenFiles . has ( host . toFullPath ( f ) ) , `Expected to write ${ f } : ${ arrayFrom ( host . writtenFiles . keys ( ) ) } ` ) ;
568
+ }
569
+
570
+ it ( "when fixing errors only changed file is emitted" , ( ) => {
571
+ const host = createSolutionWithIncrementalError ( ) ;
572
+ fixError ( host ) ;
573
+ assert . equal ( host . writtenFiles . size , 2 , `Expected to write only changed files: ${ arrayFrom ( host . writtenFiles . keys ( ) ) } ` ) ;
574
+ verifyWrittenFile ( host , outputs [ 0 ] ) ;
575
+ verifyWrittenFile ( host , outputs [ 1 ] ) ;
576
+ } ) ;
577
+
578
+ it ( "when file with no error changes, declaration errors are reported" , ( ) => {
579
+ const host = createSolutionWithIncrementalError ( ) ;
580
+ host . writeFile ( fileWithoutError . path , fileWithoutError . content . replace ( / m y C l a s s / g, "myClass2" ) ) ;
581
+ host . writtenFiles . clear ( ) ;
582
+
583
+ incrementalBuild ( host ) ;
584
+ checkOutputErrorsIncremental ( host , expectedDtsEmitErrors ) ;
585
+ assert . equal ( host . writtenFiles . size , 0 , `Expected not to write any files: ${ arrayFrom ( host . writtenFiles . keys ( ) ) } ` ) ;
586
+ } ) ;
587
+ } ) ;
588
+ } ) ;
482
589
} ) ;
483
590
484
591
describe ( "tsc-watch and tsserver works with project references" , ( ) => {
0 commit comments