@@ -504,6 +504,68 @@ describe('tree', () => {
504504 } ) ;
505505 expect ( result ) . toMatchSnapshot ( ) ;
506506 } ) ;
507+
508+ test ( 'combined: sizes + exclude' , ( ) => {
509+ const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'tree-sizes-excl-' ) ) ;
510+ fs . mkdirSync ( path . join ( tmpDir , 'included' ) ) ;
511+ fs . writeFileSync ( path . join ( tmpDir , 'included' , 'a.txt' ) , 'hello' ) ;
512+ fs . mkdirSync ( path . join ( tmpDir , 'excluded' ) ) ;
513+ fs . writeFileSync ( path . join ( tmpDir , 'excluded' , 'big.txt' ) , 'x' . repeat ( 10000 ) ) ;
514+ fs . writeFileSync ( path . join ( tmpDir , 'root.txt' ) , 'root' ) ;
515+
516+ const result = tree ( tmpDir , { sizes : true , exclude : [ / e x c l u d e d / ] } ) ;
517+ expect ( result ) . not . toContain ( 'excluded' ) ;
518+ expect ( result ) . toContain ( 'included' ) ;
519+ expect ( result ) . toContain ( 'root.txt' ) ;
520+
521+ // Directory sizes should still reflect real filesystem size (including excluded contents)
522+ const jsonResult = asDir ( treeJson ( tmpDir , { sizes : true , exclude : [ / e x c l u d e d / ] } ) ) ;
523+ expect ( jsonResult . size ) . toBeDefined ( ) ;
524+ // Root size should include the excluded directory's contents
525+ expect ( jsonResult . size ! ) . toBeGreaterThan ( 10000 ) ;
526+
527+ fs . rmSync ( tmpDir , { recursive : true } ) ;
528+ } ) ;
529+
530+ test ( 'combined: sizes + maxDepth' , ( ) => {
531+ const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'tree-sizes-depth-' ) ) ;
532+ fs . mkdirSync ( path . join ( tmpDir , 'level1' , 'level2' ) , { recursive : true } ) ;
533+ fs . writeFileSync ( path . join ( tmpDir , 'level1' , 'level2' , 'deep.txt' ) , 'x' . repeat ( 5000 ) ) ;
534+ fs . writeFileSync ( path . join ( tmpDir , 'level1' , 'shallow.txt' ) , 'hi' ) ;
535+
536+ const result = tree ( tmpDir , { sizes : true , maxDepth : 1 } ) ;
537+ // deep.txt should not be shown (beyond maxDepth)
538+ expect ( result ) . not . toContain ( 'deep.txt' ) ;
539+ expect ( result ) . toContain ( 'level1' ) ;
540+
541+ // But directory size should still include deep files
542+ const jsonResult = asDir ( treeJson ( tmpDir , { sizes : true , maxDepth : 1 } ) ) ;
543+ const level1 = jsonResult . contents . find ( ( c ) => c . name === 'level1' ) ;
544+ expect ( level1 ) . toBeDefined ( ) ;
545+ expect ( level1 ! . size ) . toBeGreaterThan ( 5000 ) ;
546+
547+ fs . rmSync ( tmpDir , { recursive : true } ) ;
548+ } ) ;
549+
550+ test ( 'combined: sizes + dirsOnly' , ( ) => {
551+ const tmpDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'tree-sizes-dirs-' ) ) ;
552+ fs . mkdirSync ( path . join ( tmpDir , 'subdir' ) ) ;
553+ fs . writeFileSync ( path . join ( tmpDir , 'subdir' , 'file.txt' ) , 'x' . repeat ( 3000 ) ) ;
554+ fs . writeFileSync ( path . join ( tmpDir , 'root.txt' ) , 'root' ) ;
555+
556+ const result = tree ( tmpDir , { sizes : true , dirsOnly : true } ) ;
557+ expect ( result ) . not . toContain ( 'file.txt' ) ;
558+ expect ( result ) . not . toContain ( 'root.txt' ) ;
559+ expect ( result ) . toContain ( 'subdir' ) ;
560+
561+ // Directory sizes should include file contents even though files aren't displayed
562+ const jsonResult = asDir ( treeJson ( tmpDir , { sizes : true , dirsOnly : true } ) ) ;
563+ const subdir = jsonResult . contents . find ( ( c ) => c . name === 'subdir' ) ;
564+ expect ( subdir ) . toBeDefined ( ) ;
565+ expect ( subdir ! . size ) . toBeGreaterThanOrEqual ( 3000 ) ;
566+
567+ fs . rmSync ( tmpDir , { recursive : true } ) ;
568+ } ) ;
507569} ) ;
508570
509571describe ( 'tree error handling' , ( ) => {
0 commit comments