Skip to content

Commit

Permalink
test: ut for label (source) => labels (mdapi)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 9, 2024
1 parent 0cbd4f8 commit b61b0a1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/convert/transformers/decomposedLabelsTransformer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { join } from 'node:path';
import { expect } from 'chai';
import { expect, assert } from 'chai';
import { parser } from '../../../src/utils/metadata';
import { stream2buffer } from '../../../src/convert/streams';
import { DecomposedLabelsFinalizer } from '../../../src/convert/convertContext/decomposedLabelsFinalizer';
import { ComponentSet } from '../../../src/collections/componentSet';
import { RegistryAccess } from '../../../src/registry/registryAccess';
import {
Expand All @@ -14,6 +17,7 @@ import {
ONLY_LABEL_CMP_IN_ANOTHER_DIR_CMP,
ONLY_LABEL_CMP_IN_DEFAULT_DIR_CMP,
ONLY_LABEL_NO_DIR_CMP,
OTHER_LABEL_CMP,
THREE_CUSTOM_LABELS_CMP,
} from '../../mock/type-constants/decomposedCustomLabelsConstant';
import {
Expand Down Expand Up @@ -129,5 +133,43 @@ describe('DecomposedCustomLabelTransformer', () => {
expect(stateEntry?.fullName).to.deep.equal(component.fullName);
});
});
describe('finalizer', () => {
it('single label from source to mdapi', async () => {
const component = ONLY_LABEL_CMP_IN_DEFAULT_DIR_CMP;
const xf = new LabelMetadataTransformer(regAcc);
await xf.toMetadataFormat(component);
const finalizer = new DecomposedLabelsFinalizer();
finalizer.customLabelsType = regAcc.getTypeByName('CustomLabels');
finalizer.transactionState = xf.context.decomposedLabels.transactionState;
const result = await finalizer.finalize();
expect(result).to.have.length(1);
expect(result[0].component.fullName).to.equal('CustomLabels');
expect(result[0].component.type.name).to.equal('CustomLabels');
expect(result[0].writeInfos).to.have.length(1);
assert(result[0].writeInfos[0].source);
const contents = (await stream2buffer(result[0].writeInfos[0].source)).toString();
expect(parser.parse(contents)).to.deep.equal(await ONE_CUSTOM_LABELS_CMP.parseXml());
});
it('2 labels from source to mdapi', async () => {
const component1 = ONLY_LABEL_CMP_IN_DEFAULT_DIR_CMP;
const component2 = OTHER_LABEL_CMP;
const xf = new LabelMetadataTransformer(regAcc);
await xf.toMetadataFormat(component1);
await xf.toMetadataFormat(component2);
const finalizer = new DecomposedLabelsFinalizer();
finalizer.customLabelsType = regAcc.getTypeByName('CustomLabels');
finalizer.transactionState = xf.context.decomposedLabels.transactionState;
const result = await finalizer.finalize();
expect(result).to.have.length(1);
expect(result[0].component.fullName).to.equal('CustomLabels');
expect(result[0].component.type.name).to.equal('CustomLabels');
// still produces only 1 writeInfo
expect(result[0].writeInfos).to.have.length(1);
assert(result[0].writeInfos[0].source);
const contents = (await stream2buffer(result[0].writeInfos[0].source)).toString();
// with 2 labels in it
expect(parser.parse(contents).CustomLabels.labels).to.have.length(2);
});
});
});
});
26 changes: 26 additions & 0 deletions test/mock/type-constants/decomposedCustomLabelsConstant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,29 @@ export const ONLY_LABEL_NO_DIR_CMP = new SourceComponent(
},
])
);

export const OTHER_LABEL_CMP = new SourceComponent(
{
name: 'OtherLabel',
type: customLabelType,
xml: join('labels', 'OtherLabel.label-meta.xml'),
},
new VirtualTreeContainer([
{
dirPath: 'labels',
children: [
{
name: 'OtherLabel.label-meta.xml',
data: Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
<CustomLabel xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>OtherLabel</fullName>
<language>en_US</language>
<protected>true</protected>
<shortDescription>OtherLabel</shortDescription>
<value>OtherLabel</value>
</CustomLabel>`),
},
],
},
])
);

2 comments on commit b61b0a1

@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: b61b0a1 Previous: 6046634 Ratio
eda-componentSetCreate-linux 254 ms 227 ms 1.12
eda-sourceToMdapi-linux 2340 ms 2283 ms 1.02
eda-sourceToZip-linux 1852 ms 1909 ms 0.97
eda-mdapiToSource-linux 2908 ms 2905 ms 1.00
lotsOfClasses-componentSetCreate-linux 423 ms 427 ms 0.99
lotsOfClasses-sourceToMdapi-linux 3728 ms 3740 ms 1.00
lotsOfClasses-sourceToZip-linux 3194 ms 3302 ms 0.97
lotsOfClasses-mdapiToSource-linux 3634 ms 3698 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 750 ms 765 ms 0.98
lotsOfClassesOneDir-sourceToMdapi-linux 6482 ms 6536 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 5704 ms 5879 ms 0.97
lotsOfClassesOneDir-mdapiToSource-linux 6573 ms 6649 ms 0.99

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: b61b0a1 Previous: 6046634 Ratio
eda-componentSetCreate-win32 619 ms 697 ms 0.89
eda-sourceToMdapi-win32 4463 ms 4763 ms 0.94
eda-sourceToZip-win32 2913 ms 3197 ms 0.91
eda-mdapiToSource-win32 5734 ms 6277 ms 0.91
lotsOfClasses-componentSetCreate-win32 1195 ms 1297 ms 0.92
lotsOfClasses-sourceToMdapi-win32 7675 ms 8432 ms 0.91
lotsOfClasses-sourceToZip-win32 5065 ms 5428 ms 0.93
lotsOfClasses-mdapiToSource-win32 7821 ms 8530 ms 0.92
lotsOfClassesOneDir-componentSetCreate-win32 2105 ms 2067 ms 1.02
lotsOfClassesOneDir-sourceToMdapi-win32 13943 ms 13841 ms 1.01
lotsOfClassesOneDir-sourceToZip-win32 9109 ms 9131 ms 1.00
lotsOfClassesOneDir-mdapiToSource-win32 14257 ms 14055 ms 1.01

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

Please sign in to comment.