@@ -9,6 +9,7 @@ import { basename, dirname, join } from 'node:path';
9
9
import { assert , expect } from 'chai' ;
10
10
import { Messages , SfError } from '@salesforce/core' ;
11
11
import { ensureString } from '@salesforce/ts-types' ;
12
+ import { createSandbox } from 'sinon' ;
12
13
import {
13
14
ComponentSet ,
14
15
MetadataResolver ,
@@ -290,6 +291,48 @@ describe('MetadataResolver', () => {
290
291
expect ( access . getComponentsFromPath ( path ) ) . to . deep . equal ( xmlInFolder . COMPONENTS ) ;
291
292
} ) ;
292
293
294
+ it ( 'should parse dirs before files' , ( ) => {
295
+ const path = xmlInFolder . COMPONENT_FOLDER_PATH ;
296
+ const env = createSandbox ( ) ;
297
+
298
+ const access = testUtil . createMetadataResolver ( [
299
+ {
300
+ dirPath : path ,
301
+ children : [ 'dir1' , { name : 'parent.report-meta.xml' , data : Buffer . from ( 'Some Data' ) } ] ,
302
+ } ,
303
+ {
304
+ dirPath : join ( path , 'dir1' ) ,
305
+ children : [ { name : 'dir1.report-meta.xml' , data : Buffer . from ( 'Some Data' ) } ] ,
306
+ } ,
307
+ ] ) ;
308
+ // @ts -ignore
309
+ const isDirSpy = env . spy ( access . tree , 'isDirectory' ) ;
310
+
311
+ const componentMappings = xmlInFolder . COMPONENTS . map ( ( c : SourceComponent ) => ( {
312
+ path : ensureString ( c . xml ) ,
313
+ component : c ,
314
+ } ) ) ;
315
+ testUtil . stubAdapters ( [
316
+ {
317
+ type : registry . types . report ,
318
+ componentMappings,
319
+ allowContent : false ,
320
+ } ,
321
+ ] ) ;
322
+ access . getComponentsFromPath ( path ) ;
323
+ // isDirectory is called a few times during recursive parsing, after debugging
324
+ // we only need to verify calls made in succession are called with dirs, and then files
325
+ expect ( [ isDirSpy . args [ 3 ] [ 0 ] , isDirSpy . args [ 4 ] [ 0 ] ] ) . to . deep . equal ( [ path , join ( path , 'parent.report-meta.xml' ) ] ) ;
326
+ expect ( [ isDirSpy . args [ 7 ] [ 0 ] , isDirSpy . args [ 8 ] [ 0 ] ] ) . to . deep . equal ( [
327
+ join ( path , 'dir1' ) ,
328
+ join ( path , 'parent.report-meta.xml' ) ,
329
+ ] ) ;
330
+ expect ( [ isDirSpy . args [ 10 ] [ 0 ] , isDirSpy . args [ 11 ] [ 0 ] ] ) . to . deep . equal ( [
331
+ join ( path , 'dir1' ) ,
332
+ join ( path , 'dir1' , 'dir1.report-meta.xml' ) ,
333
+ ] ) ;
334
+ } ) ;
335
+
293
336
it ( 'Should determine type for folder files' , ( ) => {
294
337
const path = xmlInFolder . TYPE_DIRECTORY ;
295
338
const access = testUtil . createMetadataResolver ( [
0 commit comments