@@ -58,10 +58,14 @@ function formatProgress(current: number, total: number): string {
5858
5959export class DeployStages {
6060 private mso : MultiStageOutput < Data > ;
61- private previousFailures : Set < string > ;
61+ /**
62+ * Set of Apex test failures that were already rendered in the `Running Tests` block.
63+ * This is used in the `Failed` stage block for CI output to ensure test failures aren't duplicated when rendering new failures on polling.
64+ */
65+ private printedApexTestFailures : Set < string > ;
6266
6367 public constructor ( { title, jsonEnabled, verbose } : Options ) {
64- this . previousFailures = new Set ( ) ;
68+ this . printedApexTestFailures = new Set ( ) ;
6569 this . mso = new MultiStageOutput < Data > ( {
6670 title,
6771 stages : [
@@ -154,28 +158,35 @@ export class DeployStages {
154158 {
155159 label : 'Failed' ,
156160 get : ( data ) : string | undefined => {
157- let output =
158- data ?. mdapiDeploy ?. numberTestsTotal && data ?. mdapiDeploy ?. numberTestErrors
159- ? formatProgress ( data ?. mdapiDeploy ?. numberTestErrors , data ?. mdapiDeploy ?. numberTestsTotal ) +
160- ( isCI ( )
161- ? os . EOL + formatTestFailures ( ensureArray ( data . mdapiDeploy . details . runTestResult ?. failures ) )
162- : '' )
163- : undefined ;
164-
165- console . log (
166- // @ts -ignore
167- `TO RENDER 2: ${ data ?. mdapiDeploy . details . runTestResult . failures . map ( ( f ) => `${ f . name } .${ f . methodName } ` ) } `
168- ) ;
169- console . log ( data ?. mdapiDeploy . numberTestsTotal ) ;
170- console . log ( data ?. mdapiDeploy . numberTestErrors ) ;
161+ let testFailures : Failures [ ] = [ ] ;
162+
163+ // only render new test failures
164+ if ( isCI ( ) && Array . isArray ( data ?. mdapiDeploy . details . runTestResult ?. failures ) ) {
165+ // skip failure counter/progress info if there's no new failures to render.
166+ if (
167+ this . printedApexTestFailures . size > 0 &&
168+ data . mdapiDeploy . numberTestErrors === this . printedApexTestFailures . size
169+ ) {
170+ return undefined ;
171+ }
172+
173+ testFailures = data . mdapiDeploy . details . runTestResult ?. failures . filter (
174+ ( f ) => ! this . printedApexTestFailures . has ( `${ f . name } .${ f . methodName } ` )
175+ ) ;
171176
172- if ( Array . isArray ( data ?. mdapiDeploy . details . runTestResult ?. failures ) ) {
173177 data ?. mdapiDeploy . details . runTestResult ?. failures . forEach ( ( f ) =>
174- this . previousFailures . add ( `${ f . name } .${ f . methodName } ` )
178+ this . printedApexTestFailures . add ( `${ f . name } .${ f . methodName } ` )
175179 ) ;
180+
181+ return data ?. mdapiDeploy ?. numberTestsTotal && data ?. mdapiDeploy ?. numberTestErrors
182+ ? formatProgress ( data ?. mdapiDeploy ?. numberTestErrors , data ?. mdapiDeploy ?. numberTestsTotal ) +
183+ ( isCI ( ) ? os . EOL + formatTestFailures ( testFailures ) : '' )
184+ : undefined ;
176185 }
177186
178- return output ;
187+ return data ?. mdapiDeploy ?. numberTestsTotal && data ?. mdapiDeploy ?. numberTestErrors
188+ ? formatProgress ( data ?. mdapiDeploy ?. numberTestErrors , data ?. mdapiDeploy ?. numberTestsTotal )
189+ : undefined ;
179190 } ,
180191 stage : 'Running Tests' ,
181192 type : 'dynamic-key-value' ,
@@ -219,22 +230,7 @@ export class DeployStages {
219230 data . numberTestsTotal > 0 &&
220231 data . numberComponentsDeployed > 0
221232 ) {
222- const mdapiDeploy : MetadataApiDeployStatus = {
223- ...data ,
224- } ;
225- if (
226- Array . isArray ( mdapiDeploy . details . runTestResult ?. failures ) &&
227- mdapiDeploy . details . runTestResult ?. failures . length > 0
228- ) {
229- mdapiDeploy . details . runTestResult . failures = mdapiDeploy . details . runTestResult ?. failures . filter (
230- ( f ) => ! this . previousFailures . has ( `${ f . name } .${ f . methodName } ` )
231- ) ;
232-
233- console . log (
234- `TO RENDER 1: ${ mdapiDeploy . details . runTestResult . failures . map ( ( f ) => `${ f . name } .${ f . methodName } ` ) } `
235- ) ;
236- }
237- this . mso . skipTo ( 'Running Tests' , { mdapiDeploy, status : mdTransferMessages . getMessage ( data ?. status ) } ) ;
233+ this . mso . skipTo ( 'Running Tests' , { mdapiDeploy : data , status : mdTransferMessages . getMessage ( data ?. status ) } ) ;
238234 } else if ( data . status === RequestStatus . Pending ) {
239235 this . mso . skipTo ( 'Waiting for the org to respond' , {
240236 mdapiDeploy : data ,
0 commit comments