Skip to content
Merged
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
4 changes: 4 additions & 0 deletions messages/sdr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I imagine this message needs to go through some kind of review from a tech writer?

Copy link
Contributor

Choose a reason for hiding this comment

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

@jshackell-sfdc - can you please review this?


# error_merge_metadata_target_unsupported

Merge convert for metadata target format currently unsupported
Expand Down
12 changes: 12 additions & 0 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ordinarily, I dislike putting errors in a constructor, but doing it here lets us fail faster at the immediate point of invalidity instead of waiting to do it somewhere else.

this.options = Object.assign({}, options);
this.isRestDeploy = !!options.apiOptions?.rest;
this.registry = options.registry ?? new RegistryAccess();
Expand Down Expand Up @@ -524,6 +525,17 @@ const buildFileResponsesFromComponentSet =
}
return fileResponses;
};

const validateOptions = (options: MetadataApiDeployOptions): void => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried to keep this method open-ended so we can expand on it in the future as needed.
Question: is there a reason for the const x = () => {} instead of function x() {} syntax?

Copy link
Contributor

Choose a reason for hiding this comment

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

Either are fine. Consistency at least within the file (and ideally the library) should be preferred.

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`
*/
Expand Down
2 changes: 1 addition & 1 deletion src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
24 changes: 24 additions & 0 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading