File tree 6 files changed +52
-0
lines changed
tests/baselines/reference/api
6 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ namespace ts {
72
72
/*@internal */ debugMode ?: boolean ;
73
73
setTimeout ?( callback : ( ...args : any [ ] ) => void , ms : number , ...args : any [ ] ) : any ;
74
74
clearTimeout ?( timeoutId : any ) : void ;
75
+ clearScreen ?( ) : void ;
75
76
}
76
77
77
78
export interface FileWatcher {
@@ -436,6 +437,9 @@ namespace ts {
436
437
}
437
438
438
439
const nodeSystem : System = {
440
+ clearScreen : ( ) => {
441
+ process . stdout . write ( "\x1Bc" ) ;
442
+ } ,
439
443
args : process . argv . slice ( 2 ) ,
440
444
newLine : _os . EOL ,
441
445
useCaseSensitiveFileNames,
Original file line number Diff line number Diff line change @@ -493,6 +493,10 @@ namespace ts {
493
493
}
494
494
495
495
function updateProgram ( ) {
496
+ if ( watchingHost . system . clearScreen ) {
497
+ watchingHost . system . clearScreen ( ) ;
498
+ }
499
+
496
500
timerToUpdateProgram = undefined ;
497
501
reportWatchDiagnostic ( createCompilerDiagnostic ( Diagnostics . File_change_detected_Starting_incremental_compilation ) ) ;
498
502
Original file line number Diff line number Diff line change @@ -2027,4 +2027,37 @@ declare module "fs" {
2027
2027
assert . equal ( host . readFile ( outputFile1 ) , file1 . content + host . newLine ) ;
2028
2028
} ) ;
2029
2029
} ) ;
2030
+
2031
+ describe ( "tsc-watch console clearing" , ( ) => {
2032
+ it ( "doesn't clear the console when it starts" , ( ) => {
2033
+ const file = {
2034
+ path : "f.ts" ,
2035
+ content : ""
2036
+ } ;
2037
+ const host = createWatchedSystem ( [ file ] ) ;
2038
+
2039
+ createWatchModeWithoutConfigFile ( [ file . path ] , host ) ;
2040
+ host . runQueuedTimeoutCallbacks ( ) ;
2041
+
2042
+ host . checkScreenClears ( 0 ) ;
2043
+ } ) ;
2044
+
2045
+ it ( "clears the console on recompile" , ( ) => {
2046
+ const file = {
2047
+ path : "f.ts" ,
2048
+ content : ""
2049
+ } ;
2050
+ const host = createWatchedSystem ( [ file ] ) ;
2051
+ createWatchModeWithoutConfigFile ( [ file . path ] , host ) ;
2052
+
2053
+ const modifiedFile = {
2054
+ ...file ,
2055
+ content : "//"
2056
+ } ;
2057
+ host . reloadFS ( [ modifiedFile ] ) ;
2058
+ host . runQueuedTimeoutCallbacks ( ) ;
2059
+
2060
+ host . checkScreenClears ( 1 ) ;
2061
+ } ) ;
2062
+ } ) ;
2030
2063
}
Original file line number Diff line number Diff line change @@ -251,6 +251,7 @@ interface Array<T> {}`
251
251
private toPath : ( f : string ) => Path ;
252
252
private timeoutCallbacks = new Callbacks ( ) ;
253
253
private immediateCallbacks = new Callbacks ( ) ;
254
+ private screenClears = 0 ;
254
255
255
256
readonly watchedDirectories = createMultiMap < TestDirectoryWatcher > ( ) ;
256
257
readonly watchedDirectoriesRecursive = createMultiMap < TestDirectoryWatcher > ( ) ;
@@ -604,6 +605,10 @@ interface Array<T> {}`
604
605
this . timeoutCallbacks . unregister ( timeoutId ) ;
605
606
}
606
607
608
+ clearScreen ( ) : void {
609
+ this . screenClears += 1 ;
610
+ }
611
+
607
612
checkTimeoutQueueLengthAndRun ( expected : number ) {
608
613
this . checkTimeoutQueueLength ( expected ) ;
609
614
this . runQueuedTimeoutCallbacks ( ) ;
@@ -638,6 +643,10 @@ interface Array<T> {}`
638
643
this . immediateCallbacks . unregister ( timeoutId ) ;
639
644
}
640
645
646
+ checkScreenClears ( expected : number ) : void {
647
+ assert . equal ( this . screenClears , expected ) ;
648
+ }
649
+
641
650
createDirectory ( directoryName : string ) : void {
642
651
const folder = this . toFolder ( directoryName ) ;
643
652
Original file line number Diff line number Diff line change @@ -2762,6 +2762,7 @@ declare namespace ts {
2762
2762
realpath ?( path : string ) : string ;
2763
2763
setTimeout ?( callback : ( ...args : any [ ] ) => void , ms : number , ...args : any [ ] ) : any ;
2764
2764
clearTimeout ?( timeoutId : any ) : void ;
2765
+ clearScreen ?( ) : void ;
2765
2766
}
2766
2767
interface FileWatcher {
2767
2768
close ( ) : void ;
Original file line number Diff line number Diff line change @@ -2762,6 +2762,7 @@ declare namespace ts {
2762
2762
realpath ?( path : string ) : string ;
2763
2763
setTimeout ?( callback : ( ...args : any [ ] ) => void , ms : number , ...args : any [ ] ) : any ;
2764
2764
clearTimeout ?( timeoutId : any ) : void ;
2765
+ clearScreen ?( ) : void ;
2765
2766
}
2766
2767
interface FileWatcher {
2767
2768
close ( ) : void ;
You can’t perform that action at this time.
0 commit comments