@@ -331,34 +331,47 @@ const loadOptions = (argv = []) => {
331331 args . _ = Array . from ( new Set ( args . _ ) ) ;
332332
333333 // Special handling for reporter-option: command line should override config file
334- // We need to check the original argv to see if reporter-option was specified via CLI
335- const originalArgs = Array . isArray ( argv ) ? argv : argv . split ( ' ' ) ;
336- const hasCliReporterOption = originalArgs . some ( arg =>
337- arg === '--reporter-option' || arg === '--reporter-options' ||
338- arg . startsWith ( '--reporter-option=' ) || arg . startsWith ( '--reporter-options=' )
339- ) ;
340-
341- if ( hasCliReporterOption && args [ 'reporter-option' ] && Array . isArray ( args [ 'reporter-option' ] ) ) {
342- // Find the CLI reporter-option by looking for the last occurrence in the original args
343- let cliOptionValue = null ;
344- for ( let i = originalArgs . length - 1 ; i >= 0 ; i -- ) {
345- if ( originalArgs [ i ] === '--reporter-option' || originalArgs [ i ] === '--reporter-options' ) {
334+ if ( args [ 'reporter-option' ] && Array . isArray ( args [ 'reporter-option' ] ) ) {
335+ // Start with reporter options from config file if they exist
336+ const configOptions = args [ 'reporter-option' ] . reduce ( ( acc , opt ) => {
337+ if ( typeof opt === 'string' ) {
338+ const [ key , ...values ] = opt . split ( '=' ) ;
339+ if ( key && values . length > 0 ) {
340+ acc [ key ] = values . join ( '=' ) ;
341+ }
342+ } else if ( opt && typeof opt === 'object' ) {
343+ Object . assign ( acc , opt ) ;
344+ }
345+ return acc ;
346+ } , { } ) ;
347+
348+ // Check if there are any CLI reporter options
349+ const originalArgs = Array . isArray ( argv ) ? argv : String ( argv ) . split ( ' ' ) ;
350+ const cliOptions = { } ;
351+
352+ // Process all CLI reporter options
353+ for ( let i = 0 ; i < originalArgs . length ; i ++ ) {
354+ const arg = originalArgs [ i ] ;
355+ if ( arg === '--reporter-option' || arg === '--reporter-options' ) {
346356 if ( i + 1 < originalArgs . length ) {
347- cliOptionValue = originalArgs [ i + 1 ] ;
357+ const [ key , ...values ] = originalArgs [ ++ i ] . split ( '=' ) ;
358+ if ( key && values . length > 0 ) {
359+ cliOptions [ key ] = values . join ( '=' ) ;
360+ }
361+ }
362+ } else if ( arg . startsWith ( '--reporter-option=' ) || arg . startsWith ( '--reporter-options=' ) ) {
363+ const [ key , ...values ] = arg . substring ( arg . indexOf ( '=' ) + 1 ) . split ( '=' ) ;
364+ if ( key && values . length > 0 ) {
365+ cliOptions [ key ] = values . join ( '=' ) ;
348366 }
349- break ;
350- } else if ( originalArgs [ i ] . startsWith ( '--reporter-option=' ) ) {
351- cliOptionValue = originalArgs [ i ] . substring ( originalArgs [ i ] . indexOf ( '=' ) + 1 ) ;
352- break ;
353- } else if ( originalArgs [ i ] . startsWith ( '--reporter-options=' ) ) {
354- cliOptionValue = originalArgs [ i ] . substring ( originalArgs [ i ] . indexOf ( '=' ) + 1 ) ;
355- break ;
356367 }
357368 }
369+
370+ // Merge CLI options (which take precedence) with config options
371+ const mergedOptions = { ...configOptions , ...cliOptions } ;
358372
359- if ( cliOptionValue ) {
360- args [ 'reporter-option' ] = [ cliOptionValue ] ;
361- }
373+ // Convert back to array of key=value strings
374+ args [ 'reporter-option' ] = Object . entries ( mergedOptions ) . map ( ( [ key , value ] ) => `${ key } =${ value } ` ) ;
362375 }
363376
364377 return args ;
0 commit comments