Skip to content

Commit

Permalink
fix: let server determine testlevel when deploying to a prod org by p…
Browse files Browse the repository at this point in the history
…assing `undefined` (#509)

* fix: let server determine testlevel when deploying to a prod org by passing undefined

* refactor: conditional object props

* refactor: testlevel not an array

* refactor: remove default runTests, adjust ut

* test: adjust ut

Co-authored-by: mshanemc <[email protected]>
  • Loading branch information
WillieRuemmele and mshanemc authored Jun 16, 2022
1 parent cd8d0b8 commit 6d5a995
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
26 changes: 15 additions & 11 deletions src/commands/force/mdapi/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('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<string>('testlevel') ? { testLevel: this.getFlag<TestLevel>('testlevel') } : {}),
...(this.getFlag<string[]>('runtests') ? { runTests: this.getFlag<string[]>('runtests') } : {}),
},
});
await deploy.start();
Expand Down
21 changes: 12 additions & 9 deletions src/commands/force/source/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -210,13 +208,18 @@ export class Deploy extends DeployCommand {
const deploy = await this.componentSet.deploy({
usernameOrConnection: this.org.getUsername(),
apiOptions: {
purgeOnDelete: this.getFlag<boolean>('purgeondelete', false),
ignoreWarnings: this.getFlag<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('checkonly', false),
runTests: this.getFlag<string[]>('runtests'),
testLevel: this.getFlag<TestLevel>('testlevel'),
rest: this.isRest,
...{
purgeOnDelete: this.getFlag<boolean>('purgeondelete', false),
ignoreWarnings: this.getFlag<boolean>('ignorewarnings', false),
rollbackOnError: !this.getFlag<boolean>('ignoreerrors', false),
checkOnly: this.getFlag<boolean>('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<string>('testlevel') ? { testLevel: this.getFlag<TestLevel>('testlevel') } : {}),
...(this.getFlag<string[]>('runtests') ? { runTests: this.getFlag<string[]>('runtests') } : {}),
},
});
this.asyncDeployResult = { id: deploy.id };
Expand Down
10 changes: 4 additions & 6 deletions test/commands/source/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ describe('force:source:deploy', () => {
rollbackOnError: true,
checkOnly: false,
purgeOnDelete: false,
runTests: [],
testLevel: 'NoTestRun',
rest: false,
...overrides?.apiOptions,
},
Expand Down Expand Up @@ -289,8 +287,8 @@ describe('force:source:deploy', () => {
purgeOnDelete: true,
rest: false,
rollbackOnError: false,
runTests: ['MyClassTest'],
testLevel: 'RunSpecifiedTests',
runTests,
testLevel,
},
});
ensureCreateComponentSetArgs({
Expand Down Expand Up @@ -329,8 +327,8 @@ describe('force:source:deploy', () => {
purgeOnDelete: false,
rest: false,
rollbackOnError: false,
runTests: ['MyClassTest'],
testLevel: 'RunSpecifiedTests',
runTests,
testLevel,
},
});
ensureCreateComponentSetArgs({
Expand Down

0 comments on commit 6d5a995

Please sign in to comment.