@@ -847,3 +847,90 @@ test('result when no-color flag is set', t => {
847
847
t . is ( output , expectedOutput ) ;
848
848
t . end ( ) ;
849
849
} ) ;
850
+
851
+ test ( 'successful test with logs' , t => {
852
+ const reporter = createReporter ( ) ;
853
+
854
+ const actualOutput = reporter . test ( {
855
+ title : 'successful test' ,
856
+ logs : [ 'log message 1' , 'log message 2' ]
857
+ } , { } ) ;
858
+
859
+ const expectedOutput = [
860
+ ' ' + chalk . green ( figures . tick ) + ' successful test' ,
861
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'log message 1' ) ,
862
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'log message 2' )
863
+ ] . join ( '\n' ) ;
864
+
865
+ t . is ( actualOutput , expectedOutput ) ;
866
+ t . end ( ) ;
867
+ } ) ;
868
+
869
+ test ( 'failed test with logs' , t => {
870
+ const reporter = createReporter ( ) ;
871
+
872
+ const actualOutput = reporter . test ( {
873
+ title : 'failed test' ,
874
+ error : new Error ( 'failure' ) ,
875
+ logs : [ 'log message 1' , 'log message 2' ]
876
+ } , { } ) ;
877
+
878
+ const expectedOutput = [
879
+ ' ' + chalk . red ( figures . cross ) + ' failed test ' + chalk . red ( 'failure' ) ,
880
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'log message 1' ) ,
881
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'log message 2' )
882
+ ] . join ( '\n' ) ;
883
+
884
+ t . is ( actualOutput , expectedOutput ) ;
885
+ t . end ( ) ;
886
+ } ) ;
887
+
888
+ test ( 'results with errors and logs' , t => {
889
+ const error1 = new Error ( 'error one message' ) ;
890
+ error1 . stack = beautifyStack ( error1 . stack ) ;
891
+ const err1Path = tempWrite . sync ( 'a()' ) ;
892
+ error1 . source = source ( err1Path ) ;
893
+ error1 . avaAssertionError = true ;
894
+ error1 . statements = [ ] ;
895
+ error1 . values = [
896
+ { label : 'actual:' , formatted : JSON . stringify ( 'abc' ) } ,
897
+ { label : 'expected:' , formatted : JSON . stringify ( 'abd' ) }
898
+ ] ;
899
+
900
+ const reporter = createReporter ( { color : true } ) ;
901
+ const runStatus = createRunStatus ( ) ;
902
+ runStatus . failCount = 1 ;
903
+ runStatus . tests = [ {
904
+ title : 'fail one' ,
905
+ logs : [ 'log from failed test' , 'another log from failed test' ] ,
906
+ error : error1
907
+ } ] ;
908
+
909
+ const output = reporter . finish ( runStatus ) ;
910
+ compareLineOutput ( t , output , flatten ( [
911
+ '' ,
912
+ ' ' + chalk . red ( '1 test failed' ) + time ,
913
+ '' ,
914
+ ' ' + chalk . bold . white ( 'fail one' ) ,
915
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'log from failed test' ) ,
916
+ ' ' + chalk . magenta ( figures . info ) + ' ' + chalk . gray ( 'another log from failed test' ) ,
917
+ '' ,
918
+ ' ' + chalk . grey ( `${ error1 . source . file } :${ error1 . source . line } ` ) ,
919
+ '' ,
920
+ indentString ( codeExcerpt ( error1 . source ) , 2 ) . split ( '\n' ) ,
921
+ '' ,
922
+ / e r r o r o n e m e s s a g e / ,
923
+ '' ,
924
+ ' actual:' ,
925
+ '' ,
926
+ ' "abc"' ,
927
+ '' ,
928
+ ' expected:' ,
929
+ '' ,
930
+ ' "abd"' ,
931
+ '' ,
932
+ stackLineRegex , compareLineOutput . SKIP_UNTIL_EMPTY_LINE ,
933
+ ''
934
+ ] ) ) ;
935
+ t . end ( ) ;
936
+ } ) ;
0 commit comments