@@ -50,4 +50,51 @@ describe('validateStats', () => {
5050 const { config } = validateConfig ( userConfig , mockLoadConfigInit ( ) ) ;
5151 expect ( config . outputTargets . some ( ( o ) => o . type === 'stats' ) ) . toBe ( false ) ;
5252 } ) ;
53+
54+ it ( 'adds stats from flags with custom path string' , ( ) => {
55+ // Test --stats dist/stats.json behavior
56+ userConfig . flags ! . stats = 'dist/custom-stats.json' ;
57+
58+ const { config } = validateConfig ( userConfig , mockLoadConfigInit ( ) ) ;
59+ const o = config . outputTargets . find ( ( o ) => o . type === 'stats' ) as d . OutputTargetStats ;
60+ expect ( o ) . toBeDefined ( ) ;
61+ expect ( o . file ) . toContain ( 'dist/custom-stats.json' ) ;
62+ } ) ;
63+
64+ it ( 'adds stats from flags with custom path (absolute)' , ( ) => {
65+ // Test --stats /tmp/stats.json behavior
66+ userConfig . flags ! . stats = '/tmp/absolute-stats.json' ;
67+
68+ const { config } = validateConfig ( userConfig , mockLoadConfigInit ( ) ) ;
69+ const o = config . outputTargets . find ( ( o ) => o . type === 'stats' ) as d . OutputTargetStats ;
70+ expect ( o ) . toBeDefined ( ) ;
71+ expect ( o . file ) . toBe ( '/tmp/absolute-stats.json' ) ;
72+ } ) ;
73+
74+ it ( 'flags stats path takes precedence over default when no outputTarget' , ( ) => {
75+ // When --stats has a path, it should be used instead of the default
76+ userConfig . flags ! . stats = 'custom-location/stats.json' ;
77+
78+ const { config } = validateConfig ( userConfig , mockLoadConfigInit ( ) ) ;
79+ const o = config . outputTargets . find ( ( o ) => o . type === 'stats' ) as d . OutputTargetStats ;
80+ expect ( o ) . toBeDefined ( ) ;
81+ expect ( o . file ) . toContain ( 'custom-location/stats.json' ) ;
82+ expect ( o . file ) . not . toContain ( 'stencil-stats.json' ) ;
83+ } ) ;
84+
85+ it ( 'does not override existing stats outputTarget when flag has path' , ( ) => {
86+ // When there's already a stats outputTarget in config, flag should not add another
87+ userConfig . outputTargets = [
88+ {
89+ type : 'stats' ,
90+ file : 'config-defined.json' ,
91+ } as d . OutputTargetStats ,
92+ ] ;
93+ userConfig . flags ! . stats = 'flag-defined.json' ;
94+
95+ const { config } = validateConfig ( userConfig , mockLoadConfigInit ( ) ) ;
96+ const statsTargets = config . outputTargets . filter ( ( o ) => o . type === 'stats' ) ;
97+ expect ( statsTargets . length ) . toBe ( 1 ) ;
98+ expect ( statsTargets [ 0 ] . file ) . toContain ( 'config-defined.json' ) ;
99+ } ) ;
53100} ) ;
0 commit comments