@@ -819,6 +819,107 @@ describe('Runner', () => {
819819 } ) ;
820820 } ) ;
821821
822+ it ( 'bail will terminate on the first test failure (skipping next befores)' , ( done ) => {
823+
824+ const script = Lab . script ( ) ;
825+ let beforeRan = false ;
826+ script . experiment ( 'root' , ( ) => {
827+
828+ script . experiment ( 'test' , ( ) => {
829+
830+ script . test ( '1' , ( testDone ) => {
831+
832+ testDone ( ) ;
833+ } ) ;
834+
835+ script . test ( '2' , ( testDone ) => {
836+
837+ throw new Error ( 'bailing' ) ;
838+ } ) ;
839+
840+ script . test ( '3' , ( testDone ) => {
841+
842+ testDone ( ) ;
843+ } ) ;
844+ } ) ;
845+
846+ script . experiment ( 'test' , ( ) => {
847+
848+ script . before ( ( done ) => {
849+
850+ beforeRan = true ;
851+ done ( ) ;
852+ } ) ;
853+
854+ script . test ( '1' , ( testDone ) => {
855+
856+ testDone ( ) ;
857+ } ) ;
858+ } ) ;
859+ } ) ;
860+
861+ Lab . execute ( script , { bail : true } , null , ( err , notebook ) => {
862+
863+ expect ( err ) . not . to . exist ( ) ;
864+ expect ( notebook . tests ) . to . have . length ( 4 ) ;
865+ expect ( notebook . failures ) . to . equal ( 1 ) ;
866+ expect ( notebook . tests [ 1 ] . err . message ) . to . contain ( 'bailing' ) ;
867+ expect ( notebook . tests [ 2 ] . skipped ) . to . be . true ( ) ;
868+ expect ( notebook . tests [ 3 ] . skipped ) . to . be . true ( ) ;
869+ expect ( beforeRan ) . to . be . false ( ) ;
870+ done ( ) ;
871+ } ) ;
872+ } ) ;
873+
874+ it ( 'bail will terminate on the first test failure (skipping sub-experiments)' , ( done ) => {
875+
876+ const script = Lab . script ( ) ;
877+ let beforeRan = false ;
878+ script . experiment ( 'test' , ( ) => {
879+
880+ script . test ( '1' , ( testDone ) => {
881+
882+ testDone ( ) ;
883+ } ) ;
884+
885+ script . test ( '2' , ( testDone ) => {
886+
887+ throw new Error ( 'bailing' ) ;
888+ } ) ;
889+
890+ script . test ( '3' , ( testDone ) => {
891+
892+ testDone ( ) ;
893+ } ) ;
894+
895+ script . experiment ( 'test' , ( ) => {
896+
897+ script . before ( ( done ) => {
898+
899+ beforeRan = true ;
900+ done ( ) ;
901+ } ) ;
902+
903+ script . test ( '1' , ( testDone ) => {
904+
905+ testDone ( ) ;
906+ } ) ;
907+ } ) ;
908+ } ) ;
909+
910+ Lab . execute ( script , { bail : true } , null , ( err , notebook ) => {
911+
912+ expect ( err ) . not . to . exist ( ) ;
913+ expect ( notebook . tests ) . to . have . length ( 4 ) ;
914+ expect ( notebook . failures ) . to . equal ( 1 ) ;
915+ expect ( notebook . tests [ 1 ] . err . message ) . to . contain ( 'bailing' ) ;
916+ expect ( notebook . tests [ 2 ] . skipped ) . to . be . true ( ) ;
917+ expect ( notebook . tests [ 3 ] . skipped ) . to . be . true ( ) ;
918+ expect ( beforeRan ) . to . be . false ( ) ;
919+ done ( ) ;
920+ } ) ;
921+ } ) ;
922+
822923 it ( 'dry run won\'t execute tests' , ( done ) => {
823924
824925 const script = Lab . script ( ) ;
0 commit comments