diff --git a/src/commands/force/mdapi/deploy.ts b/src/commands/force/mdapi/deploy.ts index 6791ad24b..775259164 100644 --- a/src/commands/force/mdapi/deploy.ts +++ b/src/commands/force/mdapi/deploy.ts @@ -9,7 +9,7 @@ import { flags, FlagsConfig } from '@salesforce/command'; import { Duration, env } from '@salesforce/kit'; import { Messages } from '@salesforce/core'; import { MetadataApiDeploy } from '@salesforce/source-deploy-retrieve'; -import { DeployCommand, reportsFormatters, getVersionMessage, TestLevel } from '../../../deployCommand'; +import { DeployCommand, getVersionMessage, reportsFormatters, TestLevel } from '../../../deployCommand'; import { DeployCommandAsyncResult } from '../../../formatters/source/deployAsyncResultFormatter'; import { MdDeployResult, MdDeployResultFormatter } from '../../../formatters/mdapi/mdDeployResultFormatter'; import { ProgressFormatter } from '../../../formatters/progressFormatter'; @@ -52,13 +52,11 @@ export class Deploy extends DeployCommand { description: messages.getMessage('flags.testLevel'), longDescription: messages.getMessage('flagsLong.testLevel'), options: ['NoTestRun', 'RunSpecifiedTests', 'RunLocalTests', 'RunAllTestsInOrg'], - default: 'NoTestRun', }), runtests: flags.array({ char: 'r', description: messages.getMessage('flags.runTests'), longDescription: messages.getMessage('flagsLong.runTests'), - default: [], }), ignoreerrors: flags.boolean({ char: 'o', @@ -142,14 +140,20 @@ export class Deploy extends DeployCommand { usernameOrConnection: this.org.getUsername(), ...deploymentOptions, apiOptions: { - purgeOnDelete: this.getFlag('purgeondelete', false), - ignoreWarnings: this.getFlag('ignorewarnings', false), - rollbackOnError: !this.getFlag('ignoreerrors', false), - checkOnly: this.getFlag('checkonly', false), - runTests: this.getFlag('runtests'), - testLevel: this.getFlag('testlevel'), - singlePackage: this.getFlag('singlepackage', false), - rest: this.isRest, + // properties that will always have values + ...{ + purgeOnDelete: this.getFlag('purgeondelete', false), + ignoreWarnings: this.getFlag('ignorewarnings', false), + rollbackOnError: !this.getFlag('ignoreerrors', false), + checkOnly: this.getFlag('checkonly', false), + singlePackage: this.getFlag('singlepackage', false), + rest: this.isRest, + }, + // if runTests is defaulted as 'NoTestRun' and deploying to prod, you'll get this error + // https://github.com/forcedotcom/cli/issues/1542 + // add additional properties conditionally () + ...(this.getFlag('testlevel') ? { testLevel: this.getFlag('testlevel') } : {}), + ...(this.getFlag('runtests') ? { runTests: this.getFlag('runtests') } : {}), }, }); await deploy.start(); diff --git a/src/commands/force/source/deploy.ts b/src/commands/force/source/deploy.ts index 4a4279dbd..766a4623c 100644 --- a/src/commands/force/source/deploy.ts +++ b/src/commands/force/source/deploy.ts @@ -55,13 +55,11 @@ export class Deploy extends DeployCommand { description: messages.getMessage('flags.testLevel'), longDescription: messages.getMessage('flagsLong.testLevel'), options: ['NoTestRun', 'RunSpecifiedTests', 'RunLocalTests', 'RunAllTestsInOrg'], - default: 'NoTestRun', }), runtests: flags.array({ char: 'r', description: messages.getMessage('flags.runTests'), longDescription: messages.getMessage('flagsLong.runTests'), - default: [], }), ignoreerrors: flags.boolean({ char: 'o', @@ -210,13 +208,18 @@ export class Deploy extends DeployCommand { const deploy = await this.componentSet.deploy({ usernameOrConnection: this.org.getUsername(), apiOptions: { - purgeOnDelete: this.getFlag('purgeondelete', false), - ignoreWarnings: this.getFlag('ignorewarnings', false), - rollbackOnError: !this.getFlag('ignoreerrors', false), - checkOnly: this.getFlag('checkonly', false), - runTests: this.getFlag('runtests'), - testLevel: this.getFlag('testlevel'), - rest: this.isRest, + ...{ + purgeOnDelete: this.getFlag('purgeondelete', false), + ignoreWarnings: this.getFlag('ignorewarnings', false), + rollbackOnError: !this.getFlag('ignoreerrors', false), + checkOnly: this.getFlag('checkonly', false), + rest: this.isRest, + }, + // if runTests is defaulted as 'NoTestRun' and deploying to prod, you'll get this error + // https://github.com/forcedotcom/cli/issues/1542 + // add additional properties conditionally () + ...(this.getFlag('testlevel') ? { testLevel: this.getFlag('testlevel') } : {}), + ...(this.getFlag('runtests') ? { runTests: this.getFlag('runtests') } : {}), }, }); this.asyncDeployResult = { id: deploy.id }; diff --git a/test/commands/source/deploy.test.ts b/test/commands/source/deploy.test.ts index 4381aba50..1a5149965 100644 --- a/test/commands/source/deploy.test.ts +++ b/test/commands/source/deploy.test.ts @@ -156,8 +156,6 @@ describe('force:source:deploy', () => { rollbackOnError: true, checkOnly: false, purgeOnDelete: false, - runTests: [], - testLevel: 'NoTestRun', rest: false, ...overrides?.apiOptions, }, @@ -289,8 +287,8 @@ describe('force:source:deploy', () => { purgeOnDelete: true, rest: false, rollbackOnError: false, - runTests: ['MyClassTest'], - testLevel: 'RunSpecifiedTests', + runTests, + testLevel, }, }); ensureCreateComponentSetArgs({ @@ -329,8 +327,8 @@ describe('force:source:deploy', () => { purgeOnDelete: false, rest: false, rollbackOnError: false, - runTests: ['MyClassTest'], - testLevel: 'RunSpecifiedTests', + runTests, + testLevel, }, }); ensureCreateComponentSetArgs({