diff --git a/messages/sdr.md b/messages/sdr.md index 32d31dec9..5b71679d9 100644 --- a/messages/sdr.md +++ b/messages/sdr.md @@ -22,6 +22,10 @@ Could not find parent type for %s (%s) Component conversion failed: %s +# error_invalid_test_level + +TestLevel cannot be '%s' unless API version is %s or later + # error_merge_metadata_target_unsupported Merge convert for metadata target format currently unsupported diff --git a/src/client/metadataApiDeploy.ts b/src/client/metadataApiDeploy.ts index 1e2bbb2bf..2d3ca0b6f 100644 --- a/src/client/metadataApiDeploy.ts +++ b/src/client/metadataApiDeploy.ts @@ -116,6 +116,7 @@ export class MetadataApiDeploy extends MetadataTransfer< public constructor(options: MetadataApiDeployOptions) { super(options); options.apiOptions = { ...MetadataApiDeploy.DEFAULT_OPTIONS.apiOptions, ...options.apiOptions }; + validateOptions(options); this.options = Object.assign({}, options); this.isRestDeploy = !!options.apiOptions?.rest; this.registry = options.registry ?? new RegistryAccess(); @@ -524,6 +525,17 @@ const buildFileResponsesFromComponentSet = } return fileResponses; }; + +const validateOptions = (options: MetadataApiDeployOptions): void => { + const runningRelevantTestsOnly = options.apiOptions?.testLevel === 'RunRelevantTests'; + const beforeApiV66 = options.apiVersion && Number(options.apiVersion) < 66.0; + if (runningRelevantTestsOnly && beforeApiV66) { + throw new SfError( + messages.getMessage('error_invalid_test_level', ['RunRelevantTests', '66.0']), + 'InvalidTestLevelSelection' + ); + } +}; /** * register a listener to `scopedPreDeploy` */ diff --git a/src/client/types.ts b/src/client/types.ts index 5da3ece36..dacbfd0c3 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -364,7 +364,7 @@ export type MetadataApiDeployOptions = { runAllTests?: boolean; runTests?: string[]; singlePackage?: boolean; - testLevel?: 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg'; + testLevel?: 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg' | 'RunRelevantTests'; /** * Set to true to use the REST API for deploying. */ diff --git a/test/client/metadataApiDeploy.test.ts b/test/client/metadataApiDeploy.test.ts index c8da492d7..ace098fd6 100644 --- a/test/client/metadataApiDeploy.test.ts +++ b/test/client/metadataApiDeploy.test.ts @@ -1256,6 +1256,30 @@ describe('MetadataApiDeploy', () => { expect(mdOpts.zipPath).to.equal('foo/myZip.zip'); }); + it('should disallow "RunRelevantTests" for API versions <66.0', () => { + const testCases = ['8.0', '10.0', '60.0', '65.0']; + const constructorError = { + name: 'InvalidTestLevelSelection', + message: messages.getMessage('error_invalid_test_level', ['RunRelevantTests', '66.0']), + }; + try { + testCases.forEach((v) => { + new MetadataApiDeploy({ + usernameOrConnection: 'testing', + apiOptions: { + testLevel: 'RunRelevantTests', + }, + apiVersion: v, + }); + assert.fail(`Should have thrown an error for API version ${v}`); + }); + } catch (e) { + assert(e instanceof Error); + expect(e.name).to.equal(constructorError.name); + expect(e.message).to.equal(constructorError.message); + } + }); + it('should allow mdapi path', () => { const mdApiDeploy = new MetadataApiDeploy({ usernameOrConnection: 'testing',