@@ -504,6 +504,76 @@ describe('Unit: UI', function () {
504
504
} ) ;
505
505
} ) ;
506
506
507
+ describe ( 'handles ListrErrors' , function ( ) {
508
+ const ListrError = require ( 'listr/lib/listr-error' ) ;
509
+ const errors = require ( '../../../lib/errors' ) ;
510
+
511
+ it ( 'verbose without log output' , function ( ) {
512
+ const err = new ListrError ( 'Something happened' ) ;
513
+ err . errors = [
514
+ new errors . SystemError ( 'Error 1' ) ,
515
+ new errors . SystemError ( {
516
+ message : 'Error 2' ,
517
+ task : 'Task 2'
518
+ } )
519
+ ] ;
520
+
521
+ const system = { writeErrorLog : sinon . stub ( ) } ;
522
+ const ctx = {
523
+ verbose : true ,
524
+ log : sinon . stub ( ) ,
525
+ _formatDebug : sinon . stub ( ) . returns ( 'cherries' )
526
+ } ;
527
+
528
+ ui . error . call ( ctx , err , system ) ;
529
+
530
+ expect ( ctx . log . callCount ) . to . equal ( 8 ) ;
531
+ expect ( ctx . _formatDebug . calledOnce ) . to . be . true ;
532
+ expect ( system . writeErrorLog . called ) . to . be . false ;
533
+ expect ( ctx . log . getCall ( 0 ) . args [ 0 ] ) . to . match ( / O n e o r m o r e e r r o r s o c c u r r e d / ) ;
534
+ expect ( ctx . log . getCall ( 1 ) . args [ 0 ] ) . to . match ( / 1 \) S y s t e m E r r o r / ) ;
535
+ expect ( stripAnsi ( ctx . log . getCall ( 2 ) . args [ 0 ] ) ) . to . match ( / M e s s a g e : E r r o r 1 / ) ;
536
+ expect ( ctx . log . getCall ( 3 ) . args [ 0 ] ) . to . match ( / 2 \) T a s k 2 / ) ;
537
+ expect ( stripAnsi ( ctx . log . getCall ( 4 ) . args [ 0 ] ) ) . to . match ( / M e s s a g e : E r r o r 2 / ) ;
538
+ expect ( ctx . log . getCall ( 5 ) . args [ 0 ] ) . to . equal ( 'cherries' ) ;
539
+ expect ( stripAnsi ( ctx . log . getCall ( 6 ) . args [ 0 ] ) ) . to . match ( / T r y r u n n i n g g h o s t d o c t o r t o c h e c k y o u r s y s t e m f o r k n o w n i s s u e s ./ ) ;
540
+ expect ( ctx . log . getCall ( 7 ) . args [ 0 ] ) . to . match ( / P l e a s e r e f e r t o h t t p s : \/ \/ d o c s .g h o s t .o r g / ) ;
541
+ } ) ;
542
+
543
+ it ( 'non-verbose with log output' , function ( ) {
544
+ const err = new ListrError ( 'Something happened' ) ;
545
+ err . errors = [
546
+ new errors . ProcessError ( { message : 'Error 1' } ) ,
547
+ new errors . ProcessError ( {
548
+ message : 'Error 2' ,
549
+ task : 'Task 2'
550
+ } )
551
+ ] ;
552
+
553
+ const system = { writeErrorLog : sinon . stub ( ) } ;
554
+ const ctx = {
555
+ verbose : false ,
556
+ log : sinon . stub ( ) ,
557
+ _formatDebug : sinon . stub ( ) . returns ( 'cherries' )
558
+ } ;
559
+
560
+ ui . error . call ( ctx , err , system ) ;
561
+
562
+ expect ( ctx . log . callCount ) . to . equal ( 9 ) ;
563
+ expect ( ctx . _formatDebug . calledOnce ) . to . be . true ;
564
+ expect ( system . writeErrorLog . called ) . to . be . true ;
565
+ expect ( ctx . log . getCall ( 0 ) . args [ 0 ] ) . to . match ( / O n e o r m o r e e r r o r s o c c u r r e d / ) ;
566
+ expect ( ctx . log . getCall ( 1 ) . args [ 0 ] ) . to . match ( / 1 \) P r o c e s s E r r o r / ) ;
567
+ expect ( stripAnsi ( ctx . log . getCall ( 2 ) . args [ 0 ] ) ) . to . match ( / M e s s a g e : E r r o r 1 / ) ;
568
+ expect ( ctx . log . getCall ( 3 ) . args [ 0 ] ) . to . match ( / 2 \) T a s k 2 / ) ;
569
+ expect ( stripAnsi ( ctx . log . getCall ( 4 ) . args [ 0 ] ) ) . to . match ( / M e s s a g e : E r r o r 2 / ) ;
570
+ expect ( ctx . log . getCall ( 5 ) . args [ 0 ] ) . to . equal ( 'cherries' ) ;
571
+ expect ( ctx . log . getCall ( 6 ) . args [ 0 ] ) . to . match ( / A d d i t i o n a l l o g i n f o a v a i l a b l e i n / ) ;
572
+ expect ( stripAnsi ( ctx . log . getCall ( 7 ) . args [ 0 ] ) ) . to . match ( / T r y r u n n i n g g h o s t d o c t o r t o c h e c k y o u r s y s t e m f o r k n o w n i s s u e s ./ ) ;
573
+ expect ( ctx . log . getCall ( 8 ) . args [ 0 ] ) . to . match ( / P l e a s e r e f e r t o h t t p s : \/ \/ d o c s .g h o s t .o r g / ) ;
574
+ } ) ;
575
+ } ) ;
576
+
507
577
describe ( 'handles generic errors' , function ( ) {
508
578
it ( 'verbosly' , function ( done ) {
509
579
const system = { writeErrorLog : sinon . stub ( ) } ;
0 commit comments