@@ -360,64 +360,67 @@ module.exports = function (options, callback) {
360360
361361 // initialise all the reporters
362362 ! emitter . reporters && ( emitter . reporters = { } ) ;
363- _ . isArray ( reporters ) && _ . forEach ( reporters , function ( reporterName ) {
364- // disallow duplicate reporter initialisation
365- if ( _ . has ( emitter . reporters , reporterName ) ) { return ; }
366363
367- var Reporter ;
364+ if ( _ . isArray ( reporters ) ) {
365+ _ . forEach ( reporters , function ( reporterName ) {
366+ // disallow duplicate reporter initialisation
367+ if ( _ . has ( emitter . reporters , reporterName ) ) { return ; }
368368
369- try {
370- // check if the reporter is an external reporter
371- Reporter = require ( ( function ( name ) { // ensure scoped packages are loaded
372- var prefix = '' ,
373- scope = ( name . charAt ( 0 ) === '@' ) && name . substr ( 0 , name . indexOf ( '/' ) + 1 ) ;
369+ var Reporter ;
374370
375- if ( scope ) {
376- prefix = scope ;
377- name = name . substr ( scope . length ) ;
378- }
371+ try {
372+ // check if the reporter is an external reporter
373+ Reporter = require ( ( function ( name ) { // ensure scoped packages are loaded
374+ var prefix = '' ,
375+ scope = ( name . charAt ( 0 ) === '@' ) && name . substr ( 0 , name . indexOf ( '/' ) + 1 ) ;
379376
380- return prefix + 'newman-reporter-' + name ;
381- } ( reporterName ) ) ) ;
382- }
383- // @todo - maybe have a debug mode and log error there
384- catch ( error ) {
385- if ( ! defaultReporters [ reporterName ] ) {
386- // @todo : route this via print module to respect silent flags
387- console . warn ( `newman: could not find "${ reporterName } " reporter` ) ;
388- console . warn ( ' ensure that the reporter is installed in the same directory as newman' ) ;
389-
390- // print install instruction in case a known reporter is missing
391- if ( knownReporterErrorMessages [ reporterName ] ) {
392- console . warn ( knownReporterErrorMessages [ reporterName ] ) ;
393- }
394- else {
395- console . warn ( ' please install reporter using npm\n' ) ;
377+ if ( scope ) {
378+ prefix = scope ;
379+ name = name . substr ( scope . length ) ;
380+ }
381+
382+ return prefix + 'newman-reporter-' + name ;
383+ } ( reporterName ) ) ) ;
384+ }
385+ // @todo - maybe have a debug mode and log error there
386+ catch ( error ) {
387+ if ( ! defaultReporters [ reporterName ] ) {
388+ // @todo : route this via print module to respect silent flags
389+ console . warn ( `newman: could not find "${ reporterName } " reporter` ) ;
390+ console . warn ( ' ensure that the reporter is installed in the same directory as newman' ) ;
391+
392+ // print install instruction in case a known reporter is missing
393+ if ( knownReporterErrorMessages [ reporterName ] ) {
394+ console . warn ( knownReporterErrorMessages [ reporterName ] ) ;
395+ }
396+ else {
397+ console . warn ( ' please install reporter using npm\n' ) ;
398+ }
396399 }
397400 }
398- }
399401
400- // load local reporter if its not an external reporter
401- ! Reporter && ( Reporter = defaultReporters [ reporterName ] ) ;
402+ // load local reporter if its not an external reporter
403+ ! Reporter && ( Reporter = defaultReporters [ reporterName ] ) ;
402404
403- try {
404- // we could have checked _.isFunction(Reporter), here, but we do not do that so that the nature of
405- // reporter error can be bubbled up
406- Reporter && ( emitter . reporters [ reporterName ] = new Reporter ( emitter ,
407- _ . get ( options , [ 'reporter' , reporterName ] , { } ) , options ) ) ;
408- }
409- catch ( error ) {
410- // if the reporter errored out during initialisation, we should not stop the run simply log
411- // the error stack trace for debugging
412- console . warn ( `newman: could not load "${ reporterName } " reporter` ) ;
413-
414- if ( ! defaultReporters [ reporterName ] ) {
415- // @todo : route this via print module to respect silent flags
416- console . warn ( ` this seems to be a problem in the "${ reporterName } " reporter.\n` ) ;
405+ try {
406+ // we could have checked _.isFunction(Reporter), here, but we do
407+ // not do that so that the nature of reporter error can be bubbled up
408+ Reporter && ( emitter . reporters [ reporterName ] = new Reporter ( emitter ,
409+ _ . get ( options , [ 'reporter' , reporterName ] , { } ) , options ) ) ;
417410 }
418- console . warn ( error ) ;
419- }
420- } ) ;
411+ catch ( error ) {
412+ // if the reporter errored out during initialisation, we should not stop the run simply log
413+ // the error stack trace for debugging
414+ console . warn ( `newman: could not load "${ reporterName } " reporter` ) ;
415+
416+ if ( ! defaultReporters [ reporterName ] ) {
417+ // @todo : route this via print module to respect silent flags
418+ console . warn ( ` this seems to be a problem in the "${ reporterName } " reporter.\n` ) ;
419+ }
420+ console . warn ( error ) ;
421+ }
422+ } ) ;
423+ }
421424
422425 // raise warning when more than one dominant reporters are used
423426 ( function ( reporters ) {
0 commit comments