Skip to content

Commit

Permalink
fix(deploy): print coverage warnings when source package fails
Browse files Browse the repository at this point in the history
  • Loading branch information
azlam-abdulsalam committed Mar 18, 2024
1 parent 7a8ee1a commit 3c3cacf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/sfp-cli/src/core/deployers/DeploySourceToOrgImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {

this.writeResultToReport(result);

if (this.deploymentOptions.sourceTracking) {
if (this.deploymentOptions.sourceTracking) {
await this.handleSourceTracking(this.org, this.logger, this.projectDir, result);
}

Expand All @@ -67,7 +67,10 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {

private handlErrorMesasge(result: DeployResult): string {
if (result.response.numberComponentErrors == 0) {
return 'Unable to fetch report, Check your org for details';
//Check for test coverage warnings
if (result.response.details.runTestResult.codeCoverageWarnings) {
return 'Unable to deploy due to unsatisfactory code coverage and/or test failures';
} else return 'Unable to fetch report, Check your org for details';
} else if (result.response.numberComponentErrors > 0) {
return this.constructComponentErrorMessage(result.response.details.componentFailures, this.logger);
} else if (result.response.details.runTestResult) {
Expand Down Expand Up @@ -181,7 +184,10 @@ export default class DeploySourceToOrgImpl implements DeploymentExecutor {

// Wait for polling to finish and get the DeployResult object
const hoursInWaitTime = Number(this.deploymentOptions.waitTime) / 60;
const result = await deploy.pollStatus({ frequency: Duration.seconds(30), timeout: Duration.hours(hoursInWaitTime) });
const result = await deploy.pollStatus({
frequency: Duration.seconds(30),
timeout: Duration.hours(hoursInWaitTime),
});
return result;
}

Expand Down
8 changes: 6 additions & 2 deletions packages/sfp-cli/src/core/display/DeployErrorDisplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export default class DeployErrorDisplayer {
SFPLogger.log(`Gathering Final Deployment Status`, null, logger);

if (response.numberComponentErrors == 0) {
return 'Unable to fetch report, Check your org for details';
if (response.details.runTestResult.codeCoverageWarnings) {
this.displayCodeCoverageWarnings(response.details.runTestResult.codeCoverageWarnings, logger);
return 'Unable to deploy due to unsatisfactory code coverage and/or test failures';
} else return 'Unable to fetch report, Check your org for details';
} else if (response.numberComponentErrors > 0) {
this.printMetadataFailedToDeploy(response.details.componentFailures, logger);
return response.errorMessage;
Expand All @@ -62,6 +65,7 @@ export default class DeployErrorDisplayer {
) {
let table = new Table({
head: ['Name', 'Message'],
chars: ZERO_BORDER_TABLE,
});

if (Array.isArray(codeCoverageWarnings)) {
Expand All @@ -72,7 +76,7 @@ export default class DeployErrorDisplayer {
table.push([codeCoverageWarnings['name'], codeCoverageWarnings.message]);
}

if (table.length > 1) {
if (table.length >= 1) {
SFPLogger.log(
'Unable to deploy due to unsatisfactory code coverage, Check the following classes:',
LoggerLevel.WARN,
Expand Down

0 comments on commit 3c3cacf

Please sign in to comment.