diff --git a/command-snapshot.json b/command-snapshot.json index d5918a66..a934c706 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -66,9 +66,10 @@ "installationkeybypass", "patchversion", "target-hub-org", - "targetdevhubusername" + "targetdevhubusername", + "codecoverage" ], - "flagChars": ["a", "f", "k", "m", "p", "s", "v", "w", "x"], + "flagChars": ["a", "f", "k", "m", "p", "s", "v", "w", "x", "c"], "flags": [ "api-version", "build-instance", @@ -83,7 +84,8 @@ "seed-metadata", "target-dev-hub", "verbose", - "wait" + "wait", + "code-coverage" ], "plugin": "@salesforce/plugin-packaging" }, diff --git a/messages/package_convert.md b/messages/package_convert.md index e74213a0..e136123c 100644 --- a/messages/package_convert.md +++ b/messages/package_convert.md @@ -12,6 +12,8 @@ To retrieve details about a package version create request, including status and To protect the contents of your package and to prevent unauthorized installation of your package, specify the --installation-key flag. +To promote a package version to released, you must use the --code-coverage parameter. The package must also meet the code coverage requirements. + To list package version creation requests in the org, run "<%= config.bin %> package version create list". # examples @@ -66,7 +68,7 @@ Display verbose command output. # in-progress -Request in progress. Will wait a total of %s more seconds before timing out. Current Status='%s'. +Request in progress. Will wait a total of %s more seconds before timing out. Current Status='%s'. # flags.seed-metadata.summary @@ -83,3 +85,11 @@ Specific released patch version to be converted. # flags.patch-version.description Specify a released patch version as major.minor.patch to convert to a second-generation managed package version. + +# flags.code-coverage.summary + +Calculate and store the code coverage percentage by running the packaged Apex tests included in this package version. + +# flags.code-coverage.description + +Before you can promote and release a managed package version, the Apex code must meet a minimum 75% code coverage requirement. diff --git a/package.json b/package.json index 87047b3c..de95a426 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@oclif/core": "^4", "@salesforce/core": "^8.12.0", "@salesforce/kit": "^3.2.3", - "@salesforce/packaging": "^4.6.0", + "@salesforce/packaging": "^4.7.0", "@salesforce/sf-plugins-core": "^12.2.2", "chalk": "^5.4.1" }, diff --git a/src/commands/package/convert.ts b/src/commands/package/convert.ts index 83863b6e..5ced38dc 100644 --- a/src/commands/package/convert.ts +++ b/src/commands/package/convert.ts @@ -90,6 +90,12 @@ export class PackageConvert extends SfCommand deprecateAliases: true, aliases: ['patchversion'], }), + 'code-coverage': Flags.boolean({ + char: 'c', + summary: messages.getMessage('flags.code-coverage.summary'), + description: messages.getMessage('flags.code-coverage.description'), + default: false, + }), }; public async run(): Promise { @@ -131,6 +137,7 @@ export class PackageConvert extends SfCommand buildInstance: flags['build-instance'] as string, seedMetadata: flags['seed-metadata'] as string, patchversion: flags['patch-version'] as string, + codecoverage: flags['code-coverage'] as boolean, }, project ); diff --git a/test/commands/package/packageConvert.test.ts b/test/commands/package/packageConvert.test.ts index cc2db204..3107dab2 100644 --- a/test/commands/package/packageConvert.test.ts +++ b/test/commands/package/packageConvert.test.ts @@ -7,7 +7,12 @@ import { expect } from 'chai'; import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup'; import { Config } from '@oclif/core'; -import { Package, PackageVersionCreateRequestResult, PackagingSObjects } from '@salesforce/packaging'; +import { + Package, + PackageVersionCreateRequestResult, + PackagingSObjects, + type ConvertPackageOptions, +} from '@salesforce/packaging'; import sinon from 'sinon'; import { PackageConvert } from '../../../src/commands/package/convert.js'; import Package2VersionStatus = PackagingSObjects.Package2VersionStatus; @@ -80,8 +85,10 @@ describe('package:convert', () => { ); stubSpinner(cmd); const result = await cmd.run(); - expect(spinnerStartStub.called).to.be.true; + // Check that codecoverage was passed as false + const callArgs = convertStub.getCall(0).args[2] as ConvertPackageOptions; + expect(callArgs.codecoverage).to.equal(false); expect(result).to.deep.equal(pvc); }); it('starts package version create request (success)', async () => { @@ -109,11 +116,14 @@ describe('package:convert', () => { convertStub.restore(); convertStub = $$.SANDBOX.stub(Package, 'convert').resolves(pvc); const cmd = new PackageConvert( - ['-p', CONVERTED_FROM_PACKAGE_ID, '--installation-key', INSTALL_KEY, '-v', 'test@user.com'], + ['-p', CONVERTED_FROM_PACKAGE_ID, '--installation-key', INSTALL_KEY, '-v', 'test@user.com', '-c'], config ); stubSpinner(cmd); const result = await cmd.run(); + // Check that codecoverage was passed as true + const callArgs = convertStub.getCall(0).args[2] as ConvertPackageOptions; + expect(callArgs.codecoverage).to.equal(true); expect(result).to.deep.equal(pvc); }); it('starts package version create request (error)', async () => {