Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export interface DeployOptions {
*
* _Note: Apex tests that run as part of a deployment always run synchronously and serially._
*/
testLevel?: 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg';
testLevel?: 'NoTestRun' | 'RunRelevantTests' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg';
/**
* Indicates whether the specified .zip file points to a directory
* structure with a single package (`true`) or a set of packages (`false`).
Expand Down
15 changes: 15 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,21 @@
"default": false,
"markdownDescription": "Automatically deploy metadata files to Salesforce when saved."
},
"vlocity.salesforce.productionDeployTestLevel": {
"type": "string",
"enum": [
"RunRelevantTests",
"RunLocalTests",
"RunAllTestsInOrg"
],
"default": "RunRelevantTests",
"enumDescriptions": [
"Run tests that Salesforce determines are relevant to the deployed metadata.",
"Run all local Apex tests in the production org.",
"Run all Apex tests in the production org, including managed package tests."
],
"markdownDescription": "Apex test level used for Salesforce metadata deployments to production orgs. `NoTestRun` is not available in production."
},
Comment on lines +1516 to +1530
"vlocity.salesforce.profileActionsInContextMenu": {
"type": "boolean",
"default": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import DeployMetadataCommand from '../deployMetadataCommand';

class TestDeployMetadataCommand extends DeployMetadataCommand {

public execute() {
return undefined;
}
Comment on lines +5 to +7

constructor(
private readonly productionOrg: boolean,
productionDeployTestLevel?: string
) {
super();
Object.defineProperty(this, 'vlocode', {
value: {
config: {
salesforce: {
productionDeployTestLevel
}
}
}
});
}

protected get salesforce() {
return {
isProductionOrg: async () => this.productionOrg
} as any;
}

public getOptions() {
return this.getDeploymentStartOptions();
}
}

describe('DeployMetadataCommand', () => {
it('defaults production deployments to RunRelevantTests', async () => {
await expect(new TestDeployMetadataCommand(true).getOptions()).resolves.toEqual({
ignoreWarnings: true,
testLevel: 'RunRelevantTests'
});
});
Comment on lines +37 to +42

it('uses the configured production deployment test level', async () => {
await expect(new TestDeployMetadataCommand(true, 'RunLocalTests').getOptions()).resolves.toEqual({
ignoreWarnings: true,
testLevel: 'RunLocalTests'
});
});

it('does not set a test level for non-production deployments', async () => {
await expect(new TestDeployMetadataCommand(false, 'RunLocalTests').getOptions()).resolves.toEqual({
ignoreWarnings: true
});
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from 'vscode';
import open from 'open';

import { DeployResult, RetrieveDeltaStrategy, SalesforceDeployment, SalesforcePackage, SalesforcePackageBuilder, SalesforcePackageType } from '@vlocode/salesforce';
import { DeployOptions, DeployResult, RetrieveDeltaStrategy, SalesforceDeployment, SalesforcePackage, SalesforcePackageBuilder, SalesforcePackageType } from '@vlocode/salesforce';

import { VlocodeCommand } from '../../constants';
import { ActivityProgress } from '../../lib/vlocodeActivity';
Expand Down Expand Up @@ -196,7 +196,7 @@ export default class DeployMetadataCommand extends MetadataCommand {
deployment.cancel();
});

await deployment.start({ ignoreWarnings: true });
await deployment.start(await this.getDeploymentStartOptions());
this.logger.info(`Deployment details: ${await this.vlocode.salesforceService.getPageUrl(deployment.setupUrl)}`);
const result = await deployment.getResult();

Expand All @@ -208,6 +208,14 @@ export default class DeployMetadataCommand extends MetadataCommand {
return this.onDeploymentComplete(deployment, result);
}

protected async getDeploymentStartOptions(): Promise<DeployOptions> {
const options: DeployOptions = { ignoreWarnings: true };
if (await this.salesforce.isProductionOrg()) {
options.testLevel = this.vlocode.config.salesforce.productionDeployTestLevel ?? 'RunRelevantTests';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Use a supported Metadata API test level

For production orgs that retain the new default, this sends RunRelevantTests directly to connection.metadata.deploy via SalesforceDeployment.start (packages/salesforce/src/salesforceDeployment.ts:176). That is not a Metadata API test-level value: the project's generated TestLevel definition permits only NoTestRun, RunSpecifiedTests, RunLocalTests, and RunAllTestsInOrg (packages/salesforce/src/types/metadata.ts:823). Consequently, every default production metadata deployment is rejected for an invalid testLevel; use a supported default such as RunLocalTests.

Useful? React with 👍 / 👎.

}
return options;
}
Comment on lines +211 to +217

private onDeploymentComplete(deployment: SalesforceDeployment, result: DeployResult) {
// Clear errors before starting the deployment
this.clearPreviousErrors(deployment.deploymentPackage.files());
Expand Down
1 change: 1 addition & 0 deletions packages/vscode-extension/src/lib/vlocodeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export abstract class VlocodeSalesforceConfiguration extends BaseConfiguration {
enabled: boolean;
deployOnSave: boolean;
apiVersion: string;
productionDeployTestLevel: 'RunRelevantTests' | 'RunLocalTests' | 'RunAllTestsInOrg';
manageMetaXmlFiles: boolean;
developerLogsVisible: boolean;
developerLogsAutoRefresh: boolean;
Expand Down
Loading