Skip to content

Commit

Permalink
fix: restore json result to original for code coverga
Browse files Browse the repository at this point in the history
@W-12965378@

Fix regression in package version report code coverage result in json
  • Loading branch information
peternhale committed Apr 4, 2023
1 parent 057a17b commit cd4a6fa
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"watch-extensions": "ts",
"recursive": true,
"reporter": "spec",
"timeout": 5000
"timeout": 10000
}
28 changes: 26 additions & 2 deletions schemas/package-version-report.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
"additionalProperties": false,
"properties": {
"CodeCoverage": {
"type": "string"
"anyOf": [
{
"$ref": "#/definitions/CodeCoverage"
},
{
"type": "string"
}
]
},
"HasPassedCodeCoverageCheck": {
"type": ["boolean", "string"]
Expand Down Expand Up @@ -170,7 +177,24 @@
"type": "string"
}
},
"required": ["CodeCoverage", "HasMetadataRemoved", "Package2", "Version"]
"required": ["HasMetadataRemoved", "Package2", "Version"]
},
"CodeCoverage": {
"anyOf": [
{
"type": "null"
},
{
"type": "object",
"properties": {
"apexCodeCoveragePercentage": {
"type": "number"
}
},
"required": ["apexCodeCoveragePercentage"],
"additionalProperties": false
}
]
},
"PackageType": {
"type": "string",
Expand Down
15 changes: 9 additions & 6 deletions src/commands/package/version/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { PackageVersion, PackageVersionReportResult, PackagingSObjects } from '@salesforce/packaging';
import { CodeCoverage, PackageVersion, PackageVersionReportResult, PackagingSObjects } from '@salesforce/packaging';
import * as chalk from 'chalk';
import { Optional } from '@salesforce/ts-types';
import { requiredHubFlag } from '../../../utils/hubFlag';
Expand All @@ -20,7 +20,7 @@ export type PackageVersionReportResultModified = Omit<
PackageVersionReportResult,
'CodeCoverage' | 'HasPassedCodeCoverageCheck' | 'Package2' | 'HasMetadataRemoved' | 'PackageType'
> & {
CodeCoverage: string;
CodeCoverage: CodeCoverage | string | undefined;
HasPassedCodeCoverageCheck: boolean | undefined | string;
Package2: Partial<Omit<PackagingSObjects.Package2, 'IsOrgDependent'> & { IsOrgDependent: string }>;
HasMetadataRemoved: boolean | string;
Expand Down Expand Up @@ -114,7 +114,12 @@ export class PackageVersionReportCommand extends SfCommand<PackageVersionReportR
{ key: messages.getMessage('ancestorVersion'), value: record.AncestorVersion },
{
key: pvlMessages.getMessage('codeCoverage'),
value: record.CodeCoverage,
value:
typeof record.CodeCoverage === 'string'
? record.CodeCoverage
: !record.CodeCoverage
? 'N/A'
: `${record.CodeCoverage.apexCodeCoveragePercentage.toFixed(2)}%`,
},
{
key: pvlMessages.getMessage('hasPassedCodeCoverageCheck'),
Expand Down Expand Up @@ -208,9 +213,7 @@ export class PackageVersionReportCommand extends SfCommand<PackageVersionReportR
if (results.Package2.IsOrgDependent === true || results.ValidationSkipped === true) {
record.CodeCoverage = 'N/A';
} else {
record.CodeCoverage = results.CodeCoverage?.apexCodeCoveragePercentage
? `${results.CodeCoverage?.apexCodeCoveragePercentage}%`
: 'N/A';
record.CodeCoverage = results.CodeCoverage;
}

record.HasPassedCodeCoverageCheck =
Expand Down
4 changes: 2 additions & 2 deletions test/commands/package/versionReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const pkgVersionReportResultModified: PackageVersionReportResultModified = {
Branch: '',
BuildDurationInSeconds: 10,
BuildNumber: 0,
CodeCoverage: 'N/A',
CodeCoverage: null,
CodeCoveragePercentages: {
codeCovPercentages: [
{
Expand Down Expand Up @@ -187,7 +187,7 @@ describe('package:version:report - tests', () => {
pvrrm.AncestorId = 'N/A';
pvrrm.AncestorId = 'N/A';
pvrrm.Package2.IsOrgDependent = 'N/A';
pvrrm.CodeCoverage = '33%';
pvrrm.CodeCoverage = { apexCodeCoveragePercentage: 33 };
pvrrm.HasMetadataRemoved = 'Yes';
pvrrm.HasPassedCodeCoverageCheck = 'N/A';
delete pvrrm['PackageType'];
Expand Down

0 comments on commit cd4a6fa

Please sign in to comment.