forked from forcedotcom/source-deploy-retrieve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadataResolver.test.ts
874 lines (827 loc) · 32.1 KB
/
metadataResolver.test.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { basename, dirname, join } from 'node:path';
import { assert, expect } from 'chai';
import { Messages, SfError } from '@salesforce/core';
import { ensureString } from '@salesforce/ts-types';
import {
ComponentSet,
MetadataResolver,
registry,
RegistryAccess,
SourceComponent,
VirtualDirectory,
VirtualTreeContainer,
} from '../../src';
import {
bundle,
decomposedtoplevel,
matchingContentFile,
mixedContentDirectory,
mixedContentInFolder,
xmlInFolder,
} from '../mock';
import {
DECOMPOSED_CHILD_COMPONENT_1,
DECOMPOSED_CHILD_DIR_PATH,
DECOMPOSED_CHILD_XML_PATH_1,
DECOMPOSED_CHILD_XML_PATH_2,
DECOMPOSED_COMPONENT,
DECOMPOSED_PATH,
DECOMPOSED_VIRTUAL_FS,
DECOMPOSED_XML_PATH,
} from '../mock/type-constants/customObjectConstant';
import {
MIXED_CONTENT_DIRECTORY_COMPONENT,
MIXED_CONTENT_DIRECTORY_CONTENT_PATH,
MIXED_CONTENT_DIRECTORY_DIR,
MIXED_CONTENT_DIRECTORY_VIRTUAL_FS,
MIXED_CONTENT_DIRECTORY_XML_PATHS,
} from '../mock/type-constants/staticresourceConstant';
import { META_XML_SUFFIX } from '../../src/common';
import { DE_METAFILE } from '../mock/type-constants/digitalExperienceBundleConstants';
import { RegistryTestUtil } from './registryTestUtil';
const testUtil = new RegistryTestUtil();
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');
describe('MetadataResolver', () => {
const resolver = new MetadataResolver();
const registryAccess = new RegistryAccess(registry);
describe('Should not resolve using strictDir when suffixes do not match', () => {
const type = registryAccess.getTypeByName('ApexClass');
const COMPONENT_NAMES = ['myClass'];
// real scenario: classes/foo/objects/myCls.cls (where objects is the strictDir of another type)
const TYPE_DIRECTORY = join('classes', 'subfolder', 'subfolder2', 'objects');
const XML_NAMES = COMPONENT_NAMES.map((name) => `${name}.${type.suffix}${META_XML_SUFFIX}`);
const XML_PATHS = XML_NAMES.map((name) => join(TYPE_DIRECTORY, name));
const CONTENT_NAMES = COMPONENT_NAMES.map((name) => `${name}.${type.suffix}`);
const CONTENT_PATHS = CONTENT_NAMES.map((name) => join(TYPE_DIRECTORY, name));
const TREE = new VirtualTreeContainer([
{
dirPath: TYPE_DIRECTORY,
children: XML_NAMES.concat(CONTENT_NAMES),
},
]);
const COMPONENTS = COMPONENT_NAMES.map(
(name, index) =>
new SourceComponent(
{
name,
type,
xml: XML_PATHS[index],
content: CONTENT_PATHS[index],
},
TREE
)
);
it('metadata file', () => {
const resolver = new MetadataResolver(registryAccess, TREE);
const sourceComponent = resolver.getComponentsFromPath(XML_PATHS[0])[0];
expect(sourceComponent.type).to.deep.equal(type);
expect(sourceComponent).to.deep.equal(COMPONENTS[0]);
});
it('content file', () => {
const resolver = new MetadataResolver(registryAccess, TREE);
expect(resolver.getComponentsFromPath(CONTENT_PATHS[0])).to.deep.equal([COMPONENTS[0]]);
});
});
describe('getComponentsFromPath', () => {
afterEach(() => testUtil.restore());
describe('File Paths', () => {
it('Should throw file not found error if given path does not exist', () => {
const path = matchingContentFile.CONTENT_PATHS[0];
assert.throws(
() => resolver.getComponentsFromPath(path),
SfError,
messages.getMessage('error_path_not_found', [path])
);
});
it('Should determine type for metadata file with known suffix', () => {
const path = matchingContentFile.XML_PATHS[0];
const access = testUtil.createMetadataResolver([
{
dirPath: matchingContentFile.TYPE_DIRECTORY,
children: [matchingContentFile.CONTENT_NAMES[0], matchingContentFile.XML_NAMES[0]],
},
]);
testUtil.stubAdapters([
{
type: registry.types.apexclass,
componentMappings: [
{
path,
component: matchingContentFile.COMPONENT,
},
],
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.COMPONENT]);
});
it('Should determine type for source file with known suffix', () => {
const path = matchingContentFile.CONTENT_PATHS[0];
const access = testUtil.createMetadataResolver([
{
dirPath: matchingContentFile.TYPE_DIRECTORY,
children: [matchingContentFile.CONTENT_NAMES[0], matchingContentFile.XML_NAMES[0]],
},
]);
testUtil.stubAdapters([
{
type: registry.types.apexclass,
componentMappings: [{ path, component: matchingContentFile.COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.COMPONENT]);
});
it('Should determine type for metadata file with known suffix and strictDirectoryName', () => {
// CustomSite is an example. The conditions are:
// 1. Type has "strictDirectoryName": true
// 2. Type strategy adapter is neither "mixedContent" nor "bundle"
// 3. Type doesn't have children
// 4. mdapi format file path (E_Bikes.site)
const path = join('unpackaged', 'sites', 'E_Bikes.site');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'E_Bikes',
type: registry.types.customsite,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});
it('Should determine type for source file with known suffix and strictDirectoryName', () => {
// CustomSite is an example. The conditions are:
// 1. Type has "strictDirectoryName": true
// 2. Type strategy adapter is neither "mixedContent" nor "bundle"
// 3. Type doesn't have children
// 4. source format file path (E_Bikes.site-meta.xml)
const path = join('unpackaged', 'sites', 'E_Bikes.site-meta.xml');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'E_Bikes',
type: registry.types.customsite,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});
it('Should determine type for EmailServicesFunction metadata file (mdapi format)', () => {
const path = join('unpackaged', 'emailservices', 'MyEmailServices.xml');
const treeContainer = VirtualTreeContainer.fromFilePaths([path]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const expectedComponent = new SourceComponent(
{
name: 'MyEmailServices',
type: registry.types.emailservicesfunction,
xml: path,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});
it('Should determine type for DigitalExperience metadata file (_meta.json file)', () => {
const parent = join('unpackaged', 'digitalExperiences', 'site', 'foo');
const parent_meta_file = join(parent, 'foo.digitalExperience-meta.xml');
assert(DE_METAFILE);
const path = join(parent, 'sfdc_cms__view', 'home', DE_METAFILE);
const treeContainer = VirtualTreeContainer.fromFilePaths([path, parent_meta_file]);
const mdResolver = new MetadataResolver(undefined, treeContainer);
const parentComponent = new SourceComponent(
{
name: 'site/foo',
type: registry.types.digitalexperiencebundle,
xml: parent_meta_file,
},
treeContainer
);
assert(registry.types.digitalexperiencebundle.children?.types.digitalexperience);
const expectedComponent = new SourceComponent(
{
name: 'sfdc_cms__view/home',
type: registry.types.digitalexperiencebundle.children.types.digitalexperience,
content: dirname(path),
xml: path,
parent: parentComponent,
parentType: registry.types.digitalexperiencebundle,
},
treeContainer
);
expect(mdResolver.getComponentsFromPath(path)).to.deep.equal([expectedComponent]);
});
it('Should determine type for path of mixed content type', () => {
const path = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_SOURCE_PATHS[1];
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(path),
children: [basename(path)],
},
]);
testUtil.stubAdapters([
{
type: registry.types.staticresource,
componentMappings: [{ path, component: mixedContentDirectory.MIXED_CONTENT_DIRECTORY_COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([
mixedContentDirectory.MIXED_CONTENT_DIRECTORY_COMPONENT,
]);
});
it('Should determine type for path content files', () => {
const path = matchingContentFile.CONTENT_PATHS[0];
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(path),
children: matchingContentFile.CONTENT_NAMES,
},
]);
testUtil.stubAdapters([
{
type: registry.types.apexclass,
componentMappings: [{ path, component: matchingContentFile.CONTENT_COMPONENT }],
allowContent: false,
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([matchingContentFile.CONTENT_COMPONENT]);
});
it('Should determine type for inFolder path content files', () => {
const path = xmlInFolder.COMPONENT_FOLDER_PATH;
const access = testUtil.createMetadataResolver([
{
dirPath: path,
children: xmlInFolder.XML_NAMES,
},
]);
const componentMappings = xmlInFolder.COMPONENTS.map((c: SourceComponent) => ({
path: ensureString(c.xml),
component: c,
}));
testUtil.stubAdapters([
{
type: registry.types.report,
componentMappings,
allowContent: false,
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal(xmlInFolder.COMPONENTS);
});
it('Should determine type for folder files', () => {
const path = xmlInFolder.TYPE_DIRECTORY;
const access = testUtil.createMetadataResolver([
{
dirPath: path,
children: [xmlInFolder.FOLDER_XML_NAME],
},
]);
testUtil.stubAdapters([
{
type: registry.types.reportfolder,
componentMappings: [{ path: xmlInFolder.FOLDER_XML_PATH, component: xmlInFolder.FOLDER_COMPONENT }],
allowContent: false,
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([xmlInFolder.FOLDER_COMPONENT]);
});
it('should resolve folderContentTypes (e.g. reportFolder, emailFolder) in mdapi format', () => {
const registryAccess = new RegistryAccess();
const reportFolderDir = join('unpackaged', 'reports', 'foo');
const virtualFS: VirtualDirectory[] = [{ dirPath: reportFolderDir, children: ['bar-meta.xml'] }];
const tree = new VirtualTreeContainer(virtualFS);
const mdResolver = new MetadataResolver(registryAccess, tree);
const reportFolderPath = join(reportFolderDir, 'bar-meta.xml');
const comp = mdResolver.getComponentsFromPath(reportFolderPath);
expect(comp).to.be.an('array').with.lengthOf(1);
expect(comp[0]).to.have.property('name', 'foo/bar');
expect(comp[0]).to.have.deep.property('type', registryAccess.getTypeByName('ReportFolder'));
});
it('Should not mistake folder component of a mixed content type as that type', () => {
// this test has coveage on non-mixedContent types as well by nature of the execution path
const path = mixedContentInFolder.FOLDER_XML_PATH;
const access = testUtil.createMetadataResolver([
{
dirPath: mixedContentInFolder.TYPE_DIRECTORY,
children: [basename(path)],
},
]);
testUtil.stubAdapters([
{
type: registry.types.documentfolder,
componentMappings: [{ path, component: mixedContentInFolder.FOLDER_COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path)).to.deep.equal([mixedContentInFolder.FOLDER_COMPONENT]);
});
it('Should throw type id error if one could not be determined', () => {
const missing = join('path', 'to', 'whatever', 'a.b-meta.afg');
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(missing),
children: [basename(missing)],
},
]);
assert.throws(
() => access.getComponentsFromPath(missing),
SfError,
messages.getMessage('error_could_not_infer_type', [missing])
);
});
it('Should not return a component if path to metadata xml is forceignored', () => {
const path = matchingContentFile.XML_PATHS[0];
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(path),
children: [basename(path)],
},
]);
testUtil.stubForceIgnore({ seed: path, deny: [path] });
testUtil.stubAdapters([
{
type: registry.types.apexclass,
// should not be returned
componentMappings: [{ path, component: matchingContentFile.COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path).length).to.equal(0);
});
// metadataResolver has the option to NOT use the forceIgnore file.
it('Should return a component if path to metadata xml is forceignored but forceignore is not used', () => {
const path = matchingContentFile.XML_PATHS[0];
const access = testUtil.createMetadataResolver(
[
{
dirPath: dirname(path),
children: [basename(path)],
},
],
false
);
testUtil.stubForceIgnore({ seed: path, deny: [path] });
testUtil.stubAdapters([
{
type: registry.types.apexclass,
// should not be returned
componentMappings: [{ path, component: matchingContentFile.COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path).length).to.equal(1);
});
it('Should not return a component if path to content metadata xml is forceignored', () => {
const path = matchingContentFile.XML_PATHS[0];
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(path),
children: [basename(path)],
},
]);
testUtil.stubForceIgnore({ seed: path, deny: [path] });
testUtil.stubAdapters([
{
type: registry.types.apexclass,
// should not be returned
componentMappings: [{ path, component: matchingContentFile.COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path).length).to.equal(0);
});
it('Should not return a component if path to folder metadata xml is forceignored', () => {
const path = xmlInFolder.FOLDER_XML_PATH;
const access = testUtil.createMetadataResolver([
{
dirPath: dirname(path),
children: [basename(path)],
},
]);
testUtil.stubForceIgnore({ seed: path, deny: [path] });
testUtil.stubAdapters([
{
type: registry.types.document,
// should not be returned
componentMappings: [{ path: xmlInFolder.FOLDER_XML_PATH, component: xmlInFolder.FOLDER_COMPONENT }],
},
]);
expect(access.getComponentsFromPath(path).length).to.equal(0);
});
});
describe('Directory Paths', () => {
it('Should return all components in a directory', () => {
const resolver = testUtil.createMetadataResolver([
{
dirPath: xmlInFolder.COMPONENT_FOLDER_PATH,
children: xmlInFolder.XML_NAMES,
},
]);
const componentMappings = xmlInFolder.XML_PATHS.map((p: string, i: number) => ({
path: p,
component: xmlInFolder.COMPONENTS[i],
}));
testUtil.stubAdapters([
{
type: registry.types.report,
componentMappings,
},
]);
expect(resolver.getComponentsFromPath(xmlInFolder.COMPONENT_FOLDER_PATH)).to.deep.equal(xmlInFolder.COMPONENTS);
});
it('Should walk all file and directory children', () => {
const { TYPE_DIRECTORY: apexDir } = matchingContentFile;
const populatedDir = join(apexDir, 'populated');
const emptyDir = join(apexDir, 'empty');
const documentXml = join(apexDir, xmlInFolder.XML_NAMES[0]);
const apexXml = matchingContentFile.XML_PATHS[0];
const apexContent = matchingContentFile.CONTENT_PATHS[0];
const apexBXml = join(populatedDir, matchingContentFile.XML_NAMES[1]);
const apexBContent = join(populatedDir, matchingContentFile.CONTENT_NAMES[1]);
const tree = new VirtualTreeContainer([
{
dirPath: apexDir,
children: [basename(apexXml), basename(apexContent), xmlInFolder.XML_NAMES[0], 'populated', 'empty'],
},
{
dirPath: emptyDir,
children: [],
},
{
dirPath: populatedDir,
children: [basename(apexBContent), basename(apexBXml)],
},
]);
const apexComponentB = new SourceComponent(
{
name: 'classB',
type: registry.types.apexclass,
xml: apexBXml,
content: apexBContent,
},
tree
);
const reportComponent = new SourceComponent(
{
name: 'report',
type: registry.types.report,
xml: documentXml,
},
tree
);
const access = new MetadataResolver(undefined, tree);
testUtil.stubAdapters([
{
type: registry.types.report,
componentMappings: [
{
path: join(apexDir, xmlInFolder.XML_NAMES[0]),
component: reportComponent,
},
],
},
{
type: registry.types.apexclass,
componentMappings: [
{
path: apexXml,
component: matchingContentFile.COMPONENT,
},
{
path: apexBXml,
component: apexComponentB,
},
],
},
]);
expect(access.getComponentsFromPath(apexDir)).to.deep.equal([
matchingContentFile.COMPONENT,
reportComponent,
apexComponentB,
]);
});
it('Should handle the folder of a mixed content folder type', () => {
const access = testUtil.createMetadataResolver([
{
dirPath: mixedContentInFolder.COMPONENT_FOLDER_PATH,
children: mixedContentInFolder.XML_NAMES.concat(mixedContentInFolder.CONTENT_NAMES),
},
]);
testUtil.stubAdapters([
{
type: registry.types.document,
componentMappings: [
{
path: mixedContentInFolder.XML_PATHS[0],
component: mixedContentInFolder.COMPONENTS[0],
},
{
path: mixedContentInFolder.XML_PATHS[1],
component: mixedContentInFolder.COMPONENTS[1],
},
],
},
]);
expect(access.getComponentsFromPath(mixedContentInFolder.COMPONENT_FOLDER_PATH)).to.deep.equal([
mixedContentInFolder.COMPONENTS[0],
mixedContentInFolder.COMPONENTS[1],
]);
});
it('Should return a component for a directory that is content or a child of content', () => {
const { MIXED_CONTENT_DIRECTORY_CONTENT_PATH } = mixedContentDirectory;
const access = testUtil.createMetadataResolver([
{
dirPath: MIXED_CONTENT_DIRECTORY_CONTENT_PATH,
children: [],
},
{
dirPath: mixedContentDirectory.MIXED_CONTENT_DIRECTORY_DIR,
children: [
mixedContentDirectory.MIXED_CONTENT_DIRECTORY_XML_NAMES[0],
basename(MIXED_CONTENT_DIRECTORY_CONTENT_PATH),
],
},
]);
testUtil.stubAdapters([
{
type: registry.types.staticresource,
componentMappings: [
{
path: MIXED_CONTENT_DIRECTORY_CONTENT_PATH,
component: mixedContentDirectory.MIXED_CONTENT_DIRECTORY_COMPONENT,
},
],
},
]);
expect(access.getComponentsFromPath(MIXED_CONTENT_DIRECTORY_CONTENT_PATH)).to.deep.equal([
mixedContentDirectory.MIXED_CONTENT_DIRECTORY_COMPONENT,
]);
});
it('Should not add duplicates of a component when the content has multiple -meta.xmls', () => {
const { COMPONENT, CONTENT_PATH } = bundle;
const access = testUtil.createMetadataResolver([
{
dirPath: bundle.TYPE_DIRECTORY,
children: [basename(CONTENT_PATH)],
},
{
dirPath: CONTENT_PATH,
children: bundle.SOURCE_PATHS.concat(bundle.XML_PATH).map((p) => basename(p)),
},
]);
testUtil.stubAdapters([
{
type: registry.types.auradefinitionbundle,
componentMappings: [
{ path: bundle.CONTENT_PATH, component: COMPONENT },
{ path: bundle.XML_PATH, component: COMPONENT },
{
path: bundle.SUBTYPE_XML_PATH,
component: COMPONENT,
},
],
},
]);
expect(access.getComponentsFromPath(bundle.TYPE_DIRECTORY)).to.deep.equal([COMPONENT]);
});
it('Should not add duplicate component if directory content and xml are at the same level', () => {
const access = testUtil.createMetadataResolver(MIXED_CONTENT_DIRECTORY_VIRTUAL_FS);
const component = SourceComponent.createVirtualComponent(
MIXED_CONTENT_DIRECTORY_COMPONENT,
MIXED_CONTENT_DIRECTORY_VIRTUAL_FS
);
testUtil.stubAdapters([
{
type: registry.types.staticresource,
componentMappings: [
{ path: MIXED_CONTENT_DIRECTORY_CONTENT_PATH, component },
{ path: MIXED_CONTENT_DIRECTORY_XML_PATHS[0], component },
],
},
]);
expect(access.getComponentsFromPath(MIXED_CONTENT_DIRECTORY_DIR)).to.deep.equal([component]);
});
it('should stop resolution if parent component is resolved', () => {
const access = testUtil.createMetadataResolver(DECOMPOSED_VIRTUAL_FS);
testUtil.stubAdapters([
{
type: registry.types.customobject,
componentMappings: [
{ path: DECOMPOSED_XML_PATH, component: DECOMPOSED_COMPONENT },
{ path: DECOMPOSED_CHILD_XML_PATH_1, component: DECOMPOSED_CHILD_COMPONENT_1 },
],
},
]);
expect(access.getComponentsFromPath(DECOMPOSED_PATH)).to.deep.equal([DECOMPOSED_COMPONENT]);
});
it('should return expected child SourceComponent when given a subdirectory of a folderPerType component', () => {
const tree = new VirtualTreeContainer(DECOMPOSED_VIRTUAL_FS);
const access = testUtil.createMetadataResolver(DECOMPOSED_VIRTUAL_FS);
const expectedComponent = new SourceComponent(DECOMPOSED_COMPONENT, tree);
const children = expectedComponent.getChildren();
const expectedChild = children.find((c) => c.xml === DECOMPOSED_CHILD_XML_PATH_2);
expect(access.getComponentsFromPath(DECOMPOSED_CHILD_DIR_PATH)).to.deep.equal([expectedChild]);
});
/**
* Because files of a mixed content type could have any suffix, they might collide
* with a type that uses the "suffix index" in the registry and be assigned the incorrect type.
*
* Pretend that this bundle's root xml suffix is the same as MatchingContentFile - still should be
* identified as bundle type
*/
it('should handle suffix collision for mixed content types', () => {
const tree = new VirtualTreeContainer([
{
dirPath: bundle.TYPE_DIRECTORY,
children: [basename(bundle.CONTENT_PATH)],
},
{
dirPath: bundle.CONTENT_PATH,
children: [matchingContentFile.XML_NAMES[0], basename(bundle.SOURCE_PATHS[0])],
},
]);
const access = new MetadataResolver(undefined, tree);
expect(access.getComponentsFromPath(bundle.TYPE_DIRECTORY)).to.deep.equal([
new SourceComponent(
{
name: 'myComponent',
type: registry.types.auradefinitionbundle,
xml: join(bundle.CONTENT_PATH, matchingContentFile.XML_NAMES[0]),
content: bundle.CONTENT_PATH,
},
tree
),
]);
});
it('should not return components if the directory is forceignored', () => {
const dirPath = xmlInFolder.COMPONENT_FOLDER_PATH;
testUtil.stubForceIgnore({
seed: dirPath,
deny: [join(dirPath, 'a.report-meta.xml'), join(dirPath, 'b.report-meta.xml')],
});
const access = testUtil.createMetadataResolver([
{
dirPath,
children: [xmlInFolder.XML_NAMES[0], xmlInFolder.XML_NAMES[1]],
},
]);
testUtil.stubAdapters([
{
type: registry.types.document,
componentMappings: [
{
path: xmlInFolder.XML_PATHS[0],
component: xmlInFolder.COMPONENTS[0],
},
{
path: xmlInFolder.XML_PATHS[1],
component: xmlInFolder.COMPONENTS[1],
},
],
},
]);
expect(access.getComponentsFromPath(dirPath).length).to.equal(0);
});
});
it('should ignore directories as fsPaths', () => {
// NOTE on what this test is for: When an ExperienceBundle type is retrieved
// as part of a project's metadata, but the ExperienceBundle dir and all files
// in that dir are ignored, it would throw an error. This ensures it doesn't
// throw and also doesn't resolve any components.
const dirPath = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_DIR;
const fsPath = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_CONTENT_PATH;
const topLevelXmlPath = mixedContentDirectory.MIXED_CONTENT_DIRECTORY_XML_PATHS[0];
testUtil.stubForceIgnore({ seed: dirPath, deny: [fsPath, topLevelXmlPath] });
const access = testUtil.createMetadataResolver([
{
dirPath,
children: [basename(fsPath), basename(topLevelXmlPath)],
},
{
dirPath: fsPath,
children: [],
},
]);
testUtil.stubAdapters([
{
type: registry.types.experiencebundle,
componentMappings: [
{
path: topLevelXmlPath,
component: mixedContentDirectory.MIXED_CONTENT_DIRECTORY_COMPONENT,
},
],
},
]);
expect(access.getComponentsFromPath(dirPath).length).to.equal(0);
});
describe('Filtering', () => {
it('should only return components present in filter', () => {
const resolver = testUtil.createMetadataResolver([
{
dirPath: xmlInFolder.COMPONENT_FOLDER_PATH,
children: xmlInFolder.XML_NAMES,
},
]);
const componentMappings = xmlInFolder.XML_PATHS.map((p: string, i: number) => ({
path: p,
component: xmlInFolder.COMPONENTS[i],
}));
testUtil.stubAdapters([
{
type: registry.types.report,
componentMappings,
},
]);
const toFilter = {
fullName: xmlInFolder.COMPONENTS[0].fullName,
type: registry.types.report,
};
const filter = new ComponentSet([toFilter]);
const result = resolver.getComponentsFromPath(xmlInFolder.COMPONENT_FOLDER_PATH, filter);
expect(result).to.deep.equal([xmlInFolder.COMPONENTS[0]]);
});
it('should resolve child components when present in filter', () => {
const resolver = testUtil.createMetadataResolver(decomposedtoplevel.DECOMPOSED_VIRTUAL_FS);
const children = decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT.getChildren();
const componentMappings = children.map((c: SourceComponent) => ({
path: ensureString(c.xml),
component: c,
}));
componentMappings.push({
path: decomposedtoplevel.DECOMPOSED_TOP_LEVEL_XML_PATH,
component: decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT,
});
testUtil.stubAdapters([
{
type: registry.types.customobjecttranslation,
componentMappings,
},
]);
const toFilter = [
{
fullName: children[0].fullName,
type: children[0].type,
},
{
fullName: children[1].fullName,
type: children[1].type,
},
];
const filter = new ComponentSet(toFilter);
const result = resolver.getComponentsFromPath(decomposedtoplevel.DECOMPOSED_TOP_LEVEL_COMPONENT_PATH, filter);
expect(result).to.deep.equal(children);
});
it('should resolve directory component if in filter', () => {
const resolver = new MetadataResolver(undefined, bundle.COMPONENT.tree);
testUtil.stubAdapters([
{
type: registry.types.auradefinitionbundle,
componentMappings: [
{
path: bundle.CONTENT_PATH,
component: bundle.COMPONENT,
},
],
},
]);
const filter = new ComponentSet([
{
fullName: bundle.COMPONENT.fullName,
type: bundle.COMPONENT.type,
},
]);
const result = resolver.getComponentsFromPath(bundle.TYPE_DIRECTORY, filter);
expect(result).to.deep.equal([bundle.COMPONENT]);
});
it('should not resolve directory component if not in filter', () => {
const resolver = testUtil.createMetadataResolver([
{
dirPath: bundle.TYPE_DIRECTORY,
children: [basename(bundle.CONTENT_PATH)],
},
{
dirPath: bundle.CONTENT_PATH,
children: bundle.SOURCE_PATHS.map((p) => basename(p)).concat([bundle.XML_NAME]),
},
]);
testUtil.stubAdapters([
{
type: registry.types.auradefinitionbundle,
componentMappings: [
{
path: bundle.CONTENT_PATH,
component: bundle.COMPONENT,
},
],
},
]);
const filter = new ComponentSet();
const result = resolver.getComponentsFromPath(bundle.TYPE_DIRECTORY, filter);
expect(result).to.deep.equal([]);
});
});
});
});