|
7 | 7 | import os from 'node:os'; |
8 | 8 | import { MultiStageOutput } from '@oclif/multi-stage-output'; |
9 | 9 | import { Lifecycle, Messages } from '@salesforce/core'; |
10 | | -import { MetadataApiDeploy, MetadataApiDeployStatus, RequestStatus } from '@salesforce/source-deploy-retrieve'; |
| 10 | +import { |
| 11 | + Failures, |
| 12 | + MetadataApiDeploy, |
| 13 | + MetadataApiDeployStatus, |
| 14 | + RequestStatus, |
| 15 | +} from '@salesforce/source-deploy-retrieve'; |
11 | 16 | import { SourceMemberPollingEvent } from '@salesforce/source-tracking'; |
12 | 17 | import terminalLink from 'terminal-link'; |
13 | 18 | import { ensureArray } from '@salesforce/kit'; |
@@ -53,8 +58,10 @@ function formatProgress(current: number, total: number): string { |
53 | 58 |
|
54 | 59 | export class DeployStages { |
55 | 60 | private mso: MultiStageOutput<Data>; |
| 61 | + private previousFailures: Set<string>; |
56 | 62 |
|
57 | 63 | public constructor({ title, jsonEnabled, verbose }: Options) { |
| 64 | + this.previousFailures = new Set(); |
58 | 65 | this.mso = new MultiStageOutput<Data>({ |
59 | 66 | title, |
60 | 67 | stages: [ |
@@ -146,11 +153,30 @@ export class DeployStages { |
146 | 153 | }, |
147 | 154 | { |
148 | 155 | label: 'Failed', |
149 | | - get: (data): string | undefined => |
150 | | - data?.mdapiDeploy?.numberTestsTotal && data?.mdapiDeploy?.numberTestErrors |
151 | | - ? formatProgress(data?.mdapiDeploy?.numberTestErrors, data?.mdapiDeploy?.numberTestsTotal) + |
152 | | - (isCI() ? os.EOL + formatTestFailures(data) : '') |
153 | | - : undefined, |
| 156 | + 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); |
| 171 | + |
| 172 | + if (Array.isArray(data?.mdapiDeploy.details.runTestResult?.failures)) { |
| 173 | + data?.mdapiDeploy.details.runTestResult?.failures.forEach((f) => |
| 174 | + this.previousFailures.add(`${f.name}.${f.methodName}`) |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + return output; |
| 179 | + }, |
154 | 180 | stage: 'Running Tests', |
155 | 181 | type: 'dynamic-key-value', |
156 | 182 | }, |
@@ -193,7 +219,22 @@ export class DeployStages { |
193 | 219 | data.numberTestsTotal > 0 && |
194 | 220 | data.numberComponentsDeployed > 0 |
195 | 221 | ) { |
196 | | - this.mso.skipTo('Running Tests', { mdapiDeploy: data, status: mdTransferMessages.getMessage(data?.status) }); |
| 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) }); |
197 | 238 | } else if (data.status === RequestStatus.Pending) { |
198 | 239 | this.mso.skipTo('Waiting for the org to respond', { |
199 | 240 | mdapiDeploy: data, |
@@ -265,8 +306,8 @@ function formatTestSuccesses(data: Data): string { |
265 | 306 | return output; |
266 | 307 | } |
267 | 308 |
|
268 | | -function formatTestFailures(data: Data): string { |
269 | | - const failures = ensureArray(data.mdapiDeploy.details.runTestResult?.failures).sort(testResultSort); |
| 309 | +function formatTestFailures(failuresData: Failures[]): string { |
| 310 | + const failures = failuresData.sort(testResultSort); |
270 | 311 |
|
271 | 312 | let output = ''; |
272 | 313 |
|
|
0 commit comments