@@ -59,24 +59,39 @@ function printTests(files) {
5959
6060 let numOfTests = 0 ;
6161 let numOfSuites = 0 ;
62- const filteredSuites = [ ] ;
62+ let outputString = '' ;
63+ const filterBy = process . env . grep ? process . env . grep . toLowerCase ( ) : undefined ;
6364
64- for ( const suite of mocha . suite . suites ) {
65- if ( process . env . grep && suite . title . toLowerCase ( ) . includes ( process . env . grep ) ) {
66- filteredSuites . push ( suite ) ;
65+ if ( filterBy ) {
66+ for ( const suite of mocha . suite . suites ) {
67+ const currentSuite = suite . title ;
68+ if ( suite . title . toLowerCase ( ) . includes ( filterBy ) ) {
69+ outputString += `${ colors . white . bold ( suite . title ) } -- ${ output . styles . log ( suite . file || '' ) } -- ${ mocha . suite . suites . length } tests\n` ;
70+ numOfSuites ++ ;
71+ }
72+
73+ for ( test of suite . tests ) {
74+ if ( test . title . toLowerCase ( ) . includes ( filterBy ) ) {
75+ numOfTests ++ ;
76+ outputString += `${ colors . white . bold ( test . parent . title ) } -- ${ output . styles . log ( test . parent . file || '' ) } -- ${ mocha . suite . suites . length } tests\n` ;
77+ outputString += ` ${ output . styles . scenario ( figures . checkboxOff ) } ${ test . title } \n` ;
78+ }
79+ }
6780 }
68- }
69- const displayedSuites = process . env . grep ? filteredSuites : mocha . suite . suites ;
70- for ( const suite of displayedSuites ) {
71- output . print ( `${ colors . white . bold ( suite . title ) } -- ${ output . styles . log ( suite . file || '' ) } -- ${ suite . tests . length } tests` ) ;
72- numOfSuites ++ ;
73-
74- for ( const test of suite . tests ) {
75- numOfTests ++ ;
76- output . print ( ` ${ output . styles . scenario ( figures . checkboxOff ) } ${ test . title } ` ) ;
81+ numOfSuites = countSuites ( outputString ) ;
82+ } else {
83+ for ( const suite of mocha . suite . suites ) {
84+ output . print ( `${ colors . white . bold ( suite . title ) } -- ${ output . styles . log ( suite . file || '' ) } -- ${ mocha . suite . suites . length } tests` ) ;
85+ numOfSuites ++ ;
86+
87+ for ( test of suite . tests ) {
88+ numOfTests ++ ;
89+ output . print ( ` ${ output . styles . scenario ( figures . checkboxOff ) } ${ test . title } ` ) ;
90+ }
7791 }
7892 }
7993
94+ output . print ( removeDuplicates ( outputString ) ) ;
8095 output . print ( '' ) ;
8196 output . success ( ` Total: ${ numOfSuites } suites | ${ numOfTests } tests ` ) ;
8297 printFooter ( ) ;
@@ -87,3 +102,19 @@ function printFooter() {
87102 output . print ( ) ;
88103 output . print ( '--- DRY MODE: No tests were executed ---' ) ;
89104}
105+
106+ function removeDuplicates ( inputString ) {
107+ const array = inputString . split ( '\n' ) ;
108+ const uniqueLines = [ ...new Set ( array ) ] ;
109+ const resultString = uniqueLines . join ( '\n' ) ;
110+
111+ return resultString ;
112+ }
113+
114+ function countSuites ( inputString ) {
115+ const array = inputString . split ( '\n' ) ;
116+
117+ const uniqueLines = [ ...new Set ( array ) ] ;
118+ const res = uniqueLines . filter ( item => item . includes ( '-- ' ) ) ;
119+ return res . length ;
120+ }
0 commit comments