Skip to content

Commit a7c59a2

Browse files
authored
Merge pull request #977 from salesforcecli/t/2gp-readiness/W-18760756/Add-code-coverage-option-to-convert-command
W-18760756: Adding code coverage option to the convert command
2 parents c696a47 + ebd51da commit a7c59a2

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

command-snapshot.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@
6666
"installationkeybypass",
6767
"patchversion",
6868
"target-hub-org",
69-
"targetdevhubusername"
69+
"targetdevhubusername",
70+
"codecoverage"
7071
],
71-
"flagChars": ["a", "f", "k", "m", "p", "s", "v", "w", "x"],
72+
"flagChars": ["a", "f", "k", "m", "p", "s", "v", "w", "x", "c"],
7273
"flags": [
7374
"api-version",
7475
"build-instance",
@@ -83,7 +84,8 @@
8384
"seed-metadata",
8485
"target-dev-hub",
8586
"verbose",
86-
"wait"
87+
"wait",
88+
"code-coverage"
8789
],
8890
"plugin": "@salesforce/plugin-packaging"
8991
},

messages/package_convert.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ To retrieve details about a package version create request, including status and
1212

1313
To protect the contents of your package and to prevent unauthorized installation of your package, specify the --installation-key flag.
1414

15+
To promote a package version to released, you must use the --code-coverage parameter. The package must also meet the code coverage requirements.
16+
1517
To list package version creation requests in the org, run "<%= config.bin %> package version create list".
1618

1719
# examples
@@ -66,7 +68,7 @@ Display verbose command output.
6668

6769
# in-progress
6870

69-
Request in progress. Will wait a total of %s more seconds before timing out. Current Status='%s'.
71+
Request in progress. Will wait a total of %s more seconds before timing out. Current Status='%s'.
7072

7173
# flags.seed-metadata.summary
7274

@@ -83,3 +85,11 @@ Specific released patch version to be converted.
8385
# flags.patch-version.description
8486

8587
Specify a released patch version as major.minor.patch to convert to a second-generation managed package version.
88+
89+
# flags.code-coverage.summary
90+
91+
Calculate and store the code coverage percentage by running the packaged Apex tests included in this package version.
92+
93+
# flags.code-coverage.description
94+
95+
Before you can promote and release a managed package version, the Apex code must meet a minimum 75% code coverage requirement.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"@oclif/core": "^4",
99
"@salesforce/core": "^8.12.0",
1010
"@salesforce/kit": "^3.2.3",
11-
"@salesforce/packaging": "^4.6.0",
11+
"@salesforce/packaging": "^4.7.0",
1212
"@salesforce/sf-plugins-core": "^12.2.2",
1313
"chalk": "^5.4.1"
1414
},

src/commands/package/convert.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
9090
deprecateAliases: true,
9191
aliases: ['patchversion'],
9292
}),
93+
'code-coverage': Flags.boolean({
94+
char: 'c',
95+
summary: messages.getMessage('flags.code-coverage.summary'),
96+
description: messages.getMessage('flags.code-coverage.description'),
97+
default: false,
98+
}),
9399
};
94100

95101
public async run(): Promise<PackageVersionCreateRequestResult> {
@@ -131,6 +137,7 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
131137
buildInstance: flags['build-instance'] as string,
132138
seedMetadata: flags['seed-metadata'] as string,
133139
patchversion: flags['patch-version'] as string,
140+
codecoverage: flags['code-coverage'] as boolean,
134141
},
135142
project
136143
);

test/commands/package/packageConvert.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
import { expect } from 'chai';
88
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
99
import { Config } from '@oclif/core';
10-
import { Package, PackageVersionCreateRequestResult, PackagingSObjects } from '@salesforce/packaging';
10+
import {
11+
Package,
12+
PackageVersionCreateRequestResult,
13+
PackagingSObjects,
14+
type ConvertPackageOptions,
15+
} from '@salesforce/packaging';
1116
import sinon from 'sinon';
1217
import { PackageConvert } from '../../../src/commands/package/convert.js';
1318
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus;
@@ -80,8 +85,10 @@ describe('package:convert', () => {
8085
);
8186
stubSpinner(cmd);
8287
const result = await cmd.run();
83-
8488
expect(spinnerStartStub.called).to.be.true;
89+
// Check that codecoverage was passed as false
90+
const callArgs = convertStub.getCall(0).args[2] as ConvertPackageOptions;
91+
expect(callArgs.codecoverage).to.equal(false);
8592
expect(result).to.deep.equal(pvc);
8693
});
8794
it('starts package version create request (success)', async () => {
@@ -109,11 +116,14 @@ describe('package:convert', () => {
109116
convertStub.restore();
110117
convertStub = $$.SANDBOX.stub(Package, 'convert').resolves(pvc);
111118
const cmd = new PackageConvert(
112-
['-p', CONVERTED_FROM_PACKAGE_ID, '--installation-key', INSTALL_KEY, '-v', '[email protected]'],
119+
['-p', CONVERTED_FROM_PACKAGE_ID, '--installation-key', INSTALL_KEY, '-v', '[email protected]', '-c'],
113120
config
114121
);
115122
stubSpinner(cmd);
116123
const result = await cmd.run();
124+
// Check that codecoverage was passed as true
125+
const callArgs = convertStub.getCall(0).args[2] as ConvertPackageOptions;
126+
expect(callArgs.codecoverage).to.equal(true);
117127
expect(result).to.deep.equal(pvc);
118128
});
119129
it('starts package version create request (error)', async () => {

0 commit comments

Comments
 (0)