Skip to content

Commit 7297c18

Browse files
committed
feat: added RunRelevantTests test-level @W-20152151@
1 parent f4e1d77 commit 7297c18

File tree

6 files changed

+46
-1
lines changed

6 files changed

+46
-1
lines changed

messages/sdr.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Could not find parent type for %s (%s)
2222

2323
Component conversion failed: %s
2424

25+
# error_invalid_test_level
26+
27+
TestLevel cannot be '%s' unless API version is %s or later
28+
2529
# error_merge_metadata_target_unsupported
2630

2731
Merge convert for metadata target format currently unsupported

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@salesforce/kit": "^3.2.4",
3030
"@salesforce/ts-types": "^2.0.12",
3131
"@salesforce/types": "^1.5.0",
32+
"@types/semver": "^7.7.1",
3233
"fast-levenshtein": "^3.0.0",
3334
"fast-xml-parser": "^4.5.3",
3435
"got": "^11.8.6",
@@ -38,6 +39,7 @@
3839
"mime": "2.6.0",
3940
"minimatch": "^9.0.5",
4041
"proxy-agent": "^6.4.0",
42+
"semver": "^7.7.3",
4143
"yaml": "^2.8.1"
4244
},
4345
"devDependencies": {

src/client/metadataApiDeploy.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { format } from 'node:util';
1818
import { isString } from '@salesforce/ts-types';
1919
import JSZip from 'jszip';
2020
import fs from 'graceful-fs';
21+
import semver from 'semver';
2122
import { Lifecycle } from '@salesforce/core/lifecycle';
2223
import { Messages } from '@salesforce/core/messages';
2324
import { SfError } from '@salesforce/core/sfError';
@@ -116,6 +117,7 @@ export class MetadataApiDeploy extends MetadataTransfer<
116117
public constructor(options: MetadataApiDeployOptions) {
117118
super(options);
118119
options.apiOptions = { ...MetadataApiDeploy.DEFAULT_OPTIONS.apiOptions, ...options.apiOptions };
120+
validateOptions(options);
119121
this.options = Object.assign({}, options);
120122
this.isRestDeploy = !!options.apiOptions?.rest;
121123
this.registry = options.registry ?? new RegistryAccess();
@@ -524,6 +526,17 @@ const buildFileResponsesFromComponentSet =
524526
}
525527
return fileResponses;
526528
};
529+
530+
const validateOptions = (options: MetadataApiDeployOptions): void => {
531+
const runningRelevantTestsOnly = options.apiOptions?.testLevel === 'RunRelevantTests';
532+
const beforeApiV66 = options.apiVersion && semver.lt(semver.coerce(options.apiVersion)!, '66.0.0');
533+
if (runningRelevantTestsOnly && beforeApiV66) {
534+
throw new SfError(
535+
messages.getMessage('error_invalid_test_level', ['RunRelevantTests', '66.0']),
536+
'InvalidTestLevelSelection'
537+
);
538+
}
539+
};
527540
/**
528541
* register a listener to `scopedPreDeploy`
529542
*/

src/client/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export type MetadataApiDeployOptions = {
364364
runAllTests?: boolean;
365365
runTests?: string[];
366366
singlePackage?: boolean;
367-
testLevel?: 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg';
367+
testLevel?: 'NoTestRun' | 'RunSpecifiedTests' | 'RunLocalTests' | 'RunAllTestsInOrg' | 'RunRelevantTests';
368368
/**
369369
* Set to true to use the REST API for deploying.
370370
*/

test/client/metadataApiDeploy.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,27 @@ describe('MetadataApiDeploy', () => {
12561256
expect(mdOpts.zipPath).to.equal('foo/myZip.zip');
12571257
});
12581258

1259+
it('should disallow "RunRelevantTests" for API versions <66.0', () => {
1260+
const constructorError = {
1261+
name: 'InvalidTestLevelSelection',
1262+
message: messages.getMessage('error_invalid_test_level', ['RunRelevantTests', '66.0']),
1263+
};
1264+
try {
1265+
new MetadataApiDeploy({
1266+
usernameOrConnection: 'testing',
1267+
apiOptions: {
1268+
testLevel: 'RunRelevantTests',
1269+
},
1270+
apiVersion: '8.0', // Tricksy case here: 8.0 is alphabetically after "66.0" but semantically after it.
1271+
});
1272+
assert.fail('Should have thrown an error');
1273+
} catch (e) {
1274+
assert(e instanceof Error);
1275+
expect(e.name).to.equal(constructorError.name);
1276+
expect(e.message).to.equal(constructorError.message);
1277+
}
1278+
});
1279+
12591280
it('should allow mdapi path', () => {
12601281
const mdApiDeploy = new MetadataApiDeploy({
12611282
usernameOrConnection: 'testing',

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,11 @@
10391039
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
10401040
integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==
10411041

1042+
"@types/semver@^7.7.1":
1043+
version "7.7.1"
1044+
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.7.1.tgz#3ce3af1a5524ef327d2da9e4fd8b6d95c8d70528"
1045+
integrity sha512-FmgJfu+MOcQ370SD0ev7EI8TlCAfKYU+B4m5T3yXc1CiRN94g/SZPtsCkk506aUDtlMnFZvasDwHHUcZUEaYuA==
1046+
10421047
"@types/shelljs@^0.8.15":
10431048
version "0.8.15"
10441049
resolved "https://registry.yarnpkg.com/@types/shelljs/-/shelljs-0.8.15.tgz#22c6ab9dfe05cec57d8e6cb1a95ea173aee9fcac"

0 commit comments

Comments
 (0)