forked from salesforcecli/plugin-metadata-enrichment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomponentProcessor.test.ts
More file actions
72 lines (64 loc) · 3.33 KB
/
componentProcessor.test.ts
File metadata and controls
72 lines (64 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright 2026, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { expect } from 'chai';
import type { SourceComponent } from '@salesforce/source-deploy-retrieve';
import { SourceComponentProcessor } from '@salesforce/metadata-enrichment';
function createSourceComponent(name: string, typeName: string, options?: { xml?: string }): SourceComponent {
return {
fullName: name,
name,
type: { name: typeName },
xml: options?.xml,
} as SourceComponent;
}
describe('ComponentProcessor', () => {
describe('getComponentsToSkip', () => {
it('should return empty set when sourceComponents and metadataEntries are empty', () => {
const result = SourceComponentProcessor.getComponentsToSkip([], [], undefined);
expect(result.size).to.equal(0);
});
it('should return empty set when requested LWC exists in source with xml', () => {
const source = [createSourceComponent('MyCmp', 'LightningComponentBundle', { xml: 'mycmp.js-meta.xml' })];
const result = SourceComponentProcessor.getComponentsToSkip(source, ['LightningComponentBundle:MyCmp'], undefined);
expect(result.size).to.equal(0);
});
it('should include requested component when not in source (missing)', () => {
const source = [createSourceComponent('OtherCmp', 'LightningComponentBundle', { xml: 'other.js-meta.xml' })];
const result = SourceComponentProcessor.getComponentsToSkip(source, ['LightningComponentBundle:MissingCmp'], undefined);
expect(result.size).to.be.greaterThan(0);
const skipNames = Array.from(result).map((r) => r.componentName);
expect(skipNames).to.include('MissingCmp');
});
it('should include non-LWC component in skip set', () => {
const source = [createSourceComponent('MyClass', 'ApexClass')];
const result = SourceComponentProcessor.getComponentsToSkip(source, ['ApexClass:MyClass'], undefined);
expect(result.size).to.be.greaterThan(0);
const skipEntries = Array.from(result);
expect(skipEntries.some((r) => r.componentName === 'MyClass' && r.componentType.name === 'ApexClass')).to.be.true;
});
it('should include LWC without xml in skip set', () => {
const source = [createSourceComponent('NoMetaCmp', 'LightningComponentBundle')];
const result = SourceComponentProcessor.getComponentsToSkip(source, ['LightningComponentBundle:NoMetaCmp'], undefined);
expect(result.size).to.be.greaterThan(0);
expect(Array.from(result).some((r) => r.componentName === 'NoMetaCmp')).to.be.true;
});
it('should not include wildcard metadata entries in requested (no missing from wildcard)', () => {
const source: SourceComponent[] = [];
const result = SourceComponentProcessor.getComponentsToSkip(source, ['LightningComponentBundle:*'], undefined);
expect(result.size).to.equal(0);
});
});
});