@@ -76,11 +76,11 @@ namespace ts.tscWatch {
7676 function checkOutputErrors (
7777 host : WatchedSystem ,
7878 logsBeforeWatchDiagnostic : string [ ] | undefined ,
79- preErrorsWatchDiagnostic : DiagnosticMessage ,
79+ preErrorsWatchDiagnostic : Diagnostic ,
8080 logsBeforeErrors : string [ ] | undefined ,
8181 errors : ReadonlyArray < Diagnostic > ,
8282 disableConsoleClears ?: boolean | undefined ,
83- ...postErrorsWatchDiagnostics : DiagnosticMessage [ ]
83+ ...postErrorsWatchDiagnostics : Diagnostic [ ]
8484 ) {
8585 let screenClears = 0 ;
8686 const outputs = host . getOutput ( ) ;
@@ -109,9 +109,9 @@ namespace ts.tscWatch {
109109 index ++ ;
110110 }
111111
112- function assertWatchDiagnostic ( diagnosticMessage : DiagnosticMessage ) {
113- const expected = getWatchDiagnosticWithoutDate ( diagnosticMessage ) ;
114- if ( ! disableConsoleClears && diagnosticMessage . code !== Diagnostics . Compilation_complete_Watching_for_file_changes . code ) {
112+ function assertWatchDiagnostic ( diagnostic : Diagnostic ) {
113+ const expected = getWatchDiagnosticWithoutDate ( diagnostic ) ;
114+ if ( ! disableConsoleClears && ! contains ( nonClearingMessageCodes , diagnostic . code ) ) {
115115 assert . equal ( host . screenClears [ screenClears ] , index , `Expected screen clear at this diagnostic: ${ expected } ` ) ;
116116 screenClears ++ ;
117117 }
@@ -120,24 +120,52 @@ namespace ts.tscWatch {
120120 }
121121
122122 function getOutputAtFailedMessage ( caption : string , expectedOutput : string ) {
123- return `Expected ${ caption } : ${ expectedOutput } at ${ index } in ${ JSON . stringify ( outputs ) } ` ;
123+ return `Expected ${ caption } : ${ JSON . stringify ( expectedOutput ) } at ${ index } in ${ JSON . stringify ( outputs ) } ` ;
124124 }
125125
126- function getWatchDiagnosticWithoutDate ( diagnosticMessage : DiagnosticMessage ) {
127- return ` - ${ flattenDiagnosticMessageText ( getLocaleSpecificMessage ( diagnosticMessage ) , host . newLine ) } ${ host . newLine + host . newLine + host . newLine } ` ;
126+ function getWatchDiagnosticWithoutDate ( diagnostic : Diagnostic ) {
127+ return ` - ${ flattenDiagnosticMessageText ( diagnostic . messageText , host . newLine ) } ${ host . newLine + host . newLine + host . newLine } ` ;
128128 }
129129 }
130130
131+ function createErrorsFoundCompilerDiagnostic ( errors : ReadonlyArray < Diagnostic > ) {
132+ return errors . length === 1
133+ ? createCompilerDiagnostic ( Diagnostics . Found_1_error )
134+ : createCompilerDiagnostic ( Diagnostics . Found_0_errors , errors . length ) ;
135+ }
136+
131137 function checkOutputErrorsInitial ( host : WatchedSystem , errors : ReadonlyArray < Diagnostic > , disableConsoleClears ?: boolean , logsBeforeErrors ?: string [ ] ) {
132- checkOutputErrors ( host , /*logsBeforeWatchDiagnostic*/ undefined , Diagnostics . Starting_compilation_in_watch_mode , logsBeforeErrors , errors , disableConsoleClears , Diagnostics . Compilation_complete_Watching_for_file_changes ) ;
138+ checkOutputErrors (
139+ host ,
140+ /*logsBeforeWatchDiagnostic*/ undefined ,
141+ createCompilerDiagnostic ( Diagnostics . Starting_compilation_in_watch_mode ) ,
142+ logsBeforeErrors ,
143+ errors ,
144+ disableConsoleClears ,
145+ createErrorsFoundCompilerDiagnostic ( errors ) ,
146+ createCompilerDiagnostic ( Diagnostics . Compilation_complete_Watching_for_file_changes ) ) ;
133147 }
134148
135149 function checkOutputErrorsIncremental ( host : WatchedSystem , errors : ReadonlyArray < Diagnostic > , disableConsoleClears ?: boolean , logsBeforeWatchDiagnostic ?: string [ ] , logsBeforeErrors ?: string [ ] ) {
136- checkOutputErrors ( host , logsBeforeWatchDiagnostic , Diagnostics . File_change_detected_Starting_incremental_compilation , logsBeforeErrors , errors , disableConsoleClears , Diagnostics . Compilation_complete_Watching_for_file_changes ) ;
150+ checkOutputErrors (
151+ host ,
152+ logsBeforeWatchDiagnostic ,
153+ createCompilerDiagnostic ( Diagnostics . File_change_detected_Starting_incremental_compilation ) ,
154+ logsBeforeErrors ,
155+ errors ,
156+ disableConsoleClears ,
157+ createErrorsFoundCompilerDiagnostic ( errors ) ,
158+ createCompilerDiagnostic ( Diagnostics . Compilation_complete_Watching_for_file_changes ) ) ;
137159 }
138160
139161 function checkOutputErrorsIncrementalWithExit ( host : WatchedSystem , errors : ReadonlyArray < Diagnostic > , expectedExitCode : ExitStatus , disableConsoleClears ?: boolean , logsBeforeWatchDiagnostic ?: string [ ] , logsBeforeErrors ?: string [ ] ) {
140- checkOutputErrors ( host , logsBeforeWatchDiagnostic , Diagnostics . File_change_detected_Starting_incremental_compilation , logsBeforeErrors , errors , disableConsoleClears ) ;
162+ checkOutputErrors (
163+ host ,
164+ logsBeforeWatchDiagnostic ,
165+ createCompilerDiagnostic ( Diagnostics . File_change_detected_Starting_incremental_compilation ) ,
166+ logsBeforeErrors ,
167+ errors ,
168+ disableConsoleClears ) ;
141169 assert . equal ( host . exitCode , expectedExitCode ) ;
142170 }
143171
0 commit comments