Skip to content

Commit

Permalink
chore: change error message, add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Jun 24, 2024
1 parent 84a0630 commit 3a1ca98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/resolve/sourceComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ export class SourceComponent implements MetadataComponent {
const uniqueElement = this.type.uniqueIdElement;
const matched = uniqueElement ? children.find((c) => getString(c, uniqueElement) === this.name) : undefined;
if (!matched) {
throw new SfError(`Unable to find matching parent xml file for ${this.xml}`);
throw new SfError(
`Invalid XML tags or unable to find matching parent xml file for ${this.type.name} "${this.name}"`
);
}
return matched;
}
Expand Down
20 changes: 20 additions & 0 deletions test/resolve/sourceComponent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
CHILD_1_NAME,
CHILD_1_XML,
CHILD_2_NAME,
CHILD_2_XML,
COMPONENT_1,
COMPONENT_1_XML,
COMPONENT_1_XML_PATH,
Expand All @@ -37,6 +38,7 @@ import {
} from '../mock/type-constants/customObjectTranslationConstant';
import { DecomposedSourceAdapter } from '../../src/resolve/adapters';
import { DE_METAFILE } from '../mock/type-constants/digitalExperienceBundleConstants';
import { XML_NS_KEY, XML_NS_URL } from '../../src/common';
import { RegistryTestUtil } from './registryTestUtil';

Messages.importMessagesDirectory(__dirname);
Expand Down Expand Up @@ -487,6 +489,24 @@ describe('SourceComponent', () => {
expect(COMPONENT_1.parseFromParentXml(COMPONENT_1_XML)).to.deep.equal(COMPONENT_1_XML);
});

it('throw an error when it cant find the parent xml', () => {
try {
expectedChild.parseFromParentXml({
// notice "B" not "b"
CustomLaBels: {
[XML_NS_KEY]: XML_NS_URL,
[type.directoryName]: [CHILD_1_XML, CHILD_2_XML],
},
});
assert.fail('this should throw');
} catch (e) {
assert(e instanceof Error);
expect(e.message).to.equal(
'Invalid XML tags or unable to find matching parent xml file for CustomLabel "Child_1"'
);
}
});

// https://github.com/forcedotcom/salesforcedx-vscode/issues/3210
it('should return empty children for types that do not have uniqueIdElement but xmlPathToChildren returns elements', () => {
const noUniqueIdElementType: MetadataType = JSON.parse(JSON.stringify(MATCHING_RULES_TYPE));
Expand Down

2 comments on commit 3a1ca98

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 3a1ca98 Previous: ad58712 Ratio
eda-componentSetCreate-linux 177 ms 193 ms 0.92
eda-sourceToMdapi-linux 1948 ms 2027 ms 0.96
eda-sourceToZip-linux 1787 ms 1864 ms 0.96
eda-mdapiToSource-linux 2845 ms 2929 ms 0.97
lotsOfClasses-componentSetCreate-linux 421 ms 367 ms 1.15
lotsOfClasses-sourceToMdapi-linux 3689 ms 3740 ms 0.99
lotsOfClasses-sourceToZip-linux 3027 ms 3091 ms 0.98
lotsOfClasses-mdapiToSource-linux 3481 ms 3570 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 632 ms 630 ms 1.00
lotsOfClassesOneDir-sourceToMdapi-linux 6482 ms 6594 ms 0.98
lotsOfClassesOneDir-sourceToZip-linux 5582 ms 5867 ms 0.95
lotsOfClassesOneDir-mdapiToSource-linux 6250 ms 6431 ms 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

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

Benchmark

Benchmark suite Current: 3a1ca98 Previous: ad58712 Ratio
eda-componentSetCreate-win32 397 ms 404 ms 0.98
eda-sourceToMdapi-win32 3421 ms 3425 ms 1.00
eda-sourceToZip-win32 2712 ms 2609 ms 1.04
eda-mdapiToSource-win32 5614 ms 5486 ms 1.02
lotsOfClasses-componentSetCreate-win32 897 ms 847 ms 1.06
lotsOfClasses-sourceToMdapi-win32 7564 ms 7302 ms 1.04
lotsOfClasses-sourceToZip-win32 4761 ms 4676 ms 1.02
lotsOfClasses-mdapiToSource-win32 7444 ms 7426 ms 1.00
lotsOfClassesOneDir-componentSetCreate-win32 1504 ms 1476 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-win32 13639 ms 13313 ms 1.02
lotsOfClassesOneDir-sourceToZip-win32 8869 ms 8661 ms 1.02
lotsOfClassesOneDir-mdapiToSource-win32 13646 ms 13654 ms 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.