@@ -59,24 +59,39 @@ function printTests(files) {
59
59
60
60
let numOfTests = 0 ;
61
61
let numOfSuites = 0 ;
62
- const filteredSuites = [ ] ;
62
+ let outputString = '' ;
63
+ const filterBy = process . env . grep ? process . env . grep . toLowerCase ( ) : undefined ;
63
64
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
+ }
67
80
}
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
+ }
77
91
}
78
92
}
79
93
94
+ output . print ( removeDuplicates ( outputString ) ) ;
80
95
output . print ( '' ) ;
81
96
output . success ( ` Total: ${ numOfSuites } suites | ${ numOfTests } tests ` ) ;
82
97
printFooter ( ) ;
@@ -87,3 +102,19 @@ function printFooter() {
87
102
output . print ( ) ;
88
103
output . print ( '--- DRY MODE: No tests were executed ---' ) ;
89
104
}
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