Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow to run specific tests on source delete #659

Merged
merged 12 commits into from
Jun 15, 2023
1 change: 1 addition & 0 deletions command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"source-dir",
"target-org",
"test-level",
"tests",
"track-source",
"verbose",
"wait"
Expand Down
4 changes: 4 additions & 0 deletions messages/delete.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ If the command continues to run after the wait period, the CLI returns control o
Valid values are:

- NoTestRun — No tests are run. This test level applies only to deployments to development environments, such as sandbox, Developer Edition, or trial orgs. This test level is the default for development environments.

- RunSpecifiedTests — Runs only the tests that you specify with the --tests flag. Code coverage requirements differ from the default coverage requirements when using this test level. Executed tests must comprise a minimum of 75% code coverage for each class and trigger in the deployment package. This coverage is computed for each class and trigger individually and is different than the overall coverage percentage.

- RunLocalTests — All tests in your org are run, except the ones that originate from installed managed and unlocked packages. This test level is the default for production deployments that include Apex classes or triggers.

- RunAllTestsInOrg — All tests in your org are run, including tests of managed packages.

If you don’t specify a test level, the default behavior depends on the contents of your deployment package and target org. For more information, see “Running Tests in a Deployment” in the Metadata API Developer Guide.
Expand Down
20 changes: 5 additions & 15 deletions schemas/hooks/sf-deploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
"description": "Deployables are individual pieces that can be deployed on their own. For example, each package in a salesforce project is considered a deployable that can be deployed on its own."
}
},
"required": [
"deployables"
],
"required": ["deployables"],
"additionalProperties": false
},
"DeployablePackage": {
Expand All @@ -25,9 +23,7 @@
"$ref": "#/definitions/NamedPackageDir"
}
},
"required": [
"pkg"
],
"required": ["pkg"],
"additionalProperties": false
},
"NamedPackageDir": {
Expand Down Expand Up @@ -91,11 +87,7 @@
"type": "string"
}
},
"required": [
"fullPath",
"name",
"path"
]
"required": ["fullPath", "name", "path"]
},
"PackageDirDependency": {
"type": "object",
Expand All @@ -107,10 +99,8 @@
"type": "string"
}
},
"required": [
"package"
],
"required": ["package"],
"additionalProperties": {}
}
}
}
}
10 changes: 8 additions & 2 deletions src/commands/project/delete/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ import { DeployResultFormatter } from '../../../formatters/deployResultFormatter
import { DeleteResultFormatter } from '../../../formatters/deleteResultFormatter';
import { DeployProgress } from '../../../utils/progressBar';
import { DeployCache } from '../../../utils/deployCache';
import { testLevelFlag } from '../../../utils/flags';
import { testLevelFlag, testsFlag } from '../../../utils/flags';
const fsPromises = fs.promises;
const testFlags = 'Test';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: move this to a string in the flag definition

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noticed this group should include --test-level so just reused it in that flag.


Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/plugin-deploy-retrieve', 'delete.source');
Expand Down Expand Up @@ -71,12 +72,16 @@ export class Source extends SfCommand<DeleteSourceJson> {
description: messages.getMessage('flags.wait.description'),
summary: messages.getMessage('flags.wait.summary'),
}),
tests: {
...testsFlag,
helpGroup: testFlags,
char: undefined,
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
},
'test-level': testLevelFlag({
aliases: ['testlevel'],
deprecateAliases: true,
description: messages.getMessage('flags.test-Level.description'),
summary: messages.getMessage('flags.test-Level.summary'),
options: ['NoTestRun', 'RunLocalTests', 'RunAllTestsInOrg'],
cristiand391 marked this conversation as resolved.
Show resolved Hide resolved
}),
'no-prompt': Flags.boolean({
char: 'r',
Expand Down Expand Up @@ -226,6 +231,7 @@ export class Source extends SfCommand<DeleteSourceJson> {
apiOptions: {
rest: this.isRest,
checkOnly: this.flags['check-only'] ?? false,
...(this.flags.tests ? { runTests: this.flags.tests } : {}),
...(this.flags['test-level'] ? { testLevel: this.flags['test-level'] } : {}),
},
});
Expand Down