@@ -39,34 +39,23 @@ class Reporter {
39
39
runner . on ( 'testfinished' , this . _onTestFinished . bind ( this ) ) ;
40
40
}
41
41
42
- _onStarted ( runnableTests ) {
42
+ _onStarted ( testRuns ) {
43
43
this . _testCounter = 0 ;
44
44
this . _timestamp = Date . now ( ) ;
45
45
const allTests = this . _runner . tests ( ) ;
46
- if ( allTests . length === runnableTests . length ) {
47
- console . log ( `Running all ${ colors . yellow ( runnableTests . length ) } tests on ${ colors . yellow ( this . _runner . parallel ( ) ) } worker${ this . _runner . parallel ( ) > 1 ? 's' : '' } :\n` ) ;
46
+ if ( ! this . _runner . hasFocusedTestsOrSuites ( ) ) {
47
+ console . log ( `Running all ${ colors . yellow ( testRuns . length ) } tests on ${ colors . yellow ( this . _runner . parallel ( ) ) } worker${ this . _runner . parallel ( ) > 1 ? 's' : '' } :\n` ) ;
48
48
} else {
49
- console . log ( `Running ${ colors . yellow ( runnableTests . length ) } focused tests out of total ${ colors . yellow ( allTests . length ) } on ${ colors . yellow ( this . _runner . parallel ( ) ) } worker${ this . _runner . parallel ( ) > 1 ? 's' : '' } ` ) ;
49
+ console . log ( `Running ${ colors . yellow ( testRuns . length ) } focused tests out of total ${ colors . yellow ( allTests . length ) } on ${ colors . yellow ( this . _runner . parallel ( ) ) } worker${ this . _runner . parallel ( ) > 1 ? 's' : '' } ` ) ;
50
50
console . log ( '' ) ;
51
- const focusedSuites = this . _runner . focusedSuites ( ) . map ( suite => ( {
52
- id : suite . location ( ) . filePath + ':' + suite . location ( ) . lineNumber + ':' + suite . location ( ) . columnNumber ,
53
- fullName : suite . fullName ( ) ,
54
- location : suite . location ( ) ,
55
- } ) ) ;
56
- const focusedTests = this . _runner . focusedTests ( ) . map ( test => ( {
57
- id : test . location ( ) . filePath + ':' + test . location ( ) . lineNumber + ':' + test . location ( ) . columnNumber ,
58
- fullName : test . fullName ( ) ,
59
- location : test . location ( ) ,
60
- } ) ) ;
61
- const focusedEntities = new Map ( [
62
- ...focusedSuites . map ( suite => ( [ suite . id , suite ] ) ) ,
63
- ...focusedTests . map ( test => ( [ test . id , test ] ) ) ,
64
- ] ) ;
65
- if ( focusedEntities . size ) {
51
+ const focusedEntities = [
52
+ ...this . _runner . suites ( ) . filter ( suite => suite . focused ( ) ) ,
53
+ ...this . _runner . tests ( ) . filter ( test => test . focused ( ) ) ,
54
+ ] ;
55
+ if ( focusedEntities . length ) {
66
56
console . log ( 'Focused Suites and Tests:' ) ;
67
- const entities = [ ...focusedEntities . values ( ) ] ;
68
- for ( let i = 0 ; i < entities . length ; ++ i )
69
- console . log ( ` ${ i + 1 } ) ${ entities [ i ] . fullName } (${ formatLocation ( entities [ i ] . location ) } )` ) ;
57
+ for ( let i = 0 ; i < focusedEntities . length ; ++ i )
58
+ console . log ( ` ${ i + 1 } ) ${ focusedEntities [ i ] . fullName ( ) } (${ formatLocation ( focusedEntities [ i ] . location ( ) ) } )` ) ;
70
59
console . log ( '' ) ;
71
60
}
72
61
}
@@ -80,168 +69,164 @@ class Reporter {
80
69
}
81
70
82
71
for ( let i = 0 ; i < result . errors . length ; i ++ ) {
83
- const { message, error, workerId , tests } = result . errors [ i ] ;
72
+ const { message, error, runs } = result . errors [ i ] ;
84
73
console . log ( `\n${ colors . magenta ( 'NON-TEST ERROR #' + i ) } : ${ message } ` ) ;
85
74
if ( error && error . stack )
86
75
console . log ( padLines ( error . stack , 2 ) ) ;
87
- const lastTests = tests . slice ( tests . length - Math . min ( 10 , tests . length ) ) ;
88
- if ( lastTests . length )
76
+ const lastRuns = runs . slice ( runs . length - Math . min ( 10 , runs . length ) ) ;
77
+ if ( lastRuns . length )
89
78
console . log ( `WORKER STATE` ) ;
90
- for ( let j = 0 ; j < lastTests . length ; j ++ )
91
- this . _printVerboseTestResult ( j , lastTests [ j ] , workerId ) ;
79
+ for ( let j = 0 ; j < lastRuns . length ; j ++ )
80
+ this . _printVerboseTestRunResult ( j , lastRuns [ j ] ) ;
92
81
}
93
82
console . log ( '' ) ;
94
83
console . log ( '' ) ;
95
84
}
96
85
97
86
_onFinished ( result ) {
98
- this . _printTestResults ( ) ;
87
+ this . _printTestResults ( result ) ;
99
88
if ( ! result . ok ( ) )
100
89
this . _printFailedResult ( result ) ;
101
90
process . exitCode = result . exitCode ;
102
91
}
103
92
104
- _printTestResults ( ) {
93
+ _printTestResults ( result ) {
105
94
// 2 newlines after completing all tests.
106
95
console . log ( '\n' ) ;
107
96
108
- const failedTests = this . _runner . failedTests ( ) ;
109
- if ( this . _summary && failedTests . length > 0 ) {
97
+ const runs = result . runs ;
98
+ const failedRuns = runs . filter ( run => run . isFailure ( ) ) ;
99
+ const executedRuns = runs . filter ( run => run . result ( ) ) ;
100
+ const okRuns = runs . filter ( run => run . ok ( ) ) ;
101
+ const skippedRuns = runs . filter ( run => run . result ( ) === 'skipped' ) ;
102
+ const markedAsFailingRuns = runs . filter ( run => run . result ( ) === 'markedAsFailing' ) ;
103
+
104
+ if ( this . _summary && failedRuns . length > 0 ) {
110
105
console . log ( '\nFailures:' ) ;
111
- for ( let i = 0 ; i < failedTests . length ; ++ i ) {
112
- const test = failedTests [ i ] ;
113
- this . _printVerboseTestResult ( i + 1 , test ) ;
106
+ for ( let i = 0 ; i < failedRuns . length ; ++ i ) {
107
+ this . _printVerboseTestRunResult ( i + 1 , failedRuns [ i ] ) ;
114
108
console . log ( '' ) ;
115
109
}
116
110
}
117
111
118
- const skippedTests = this . _runner . skippedTests ( ) ;
119
- const markedAsFailingTests = this . _runner . markedAsFailingTests ( ) ;
120
- if ( this . _showMarkedAsFailingTests && this . _summary && markedAsFailingTests . length ) {
121
- if ( markedAsFailingTests . length > 0 ) {
112
+ if ( this . _showMarkedAsFailingTests && this . _summary && markedAsFailingRuns . length ) {
113
+ if ( markedAsFailingRuns . length > 0 ) {
122
114
console . log ( '\nMarked as failing:' ) ;
123
- markedAsFailingTests . slice ( 0 , this . _showMarkedAsFailingTests ) . forEach ( ( test , index ) => {
124
- console . log ( `${ index + 1 } ) ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
115
+ markedAsFailingRuns . slice ( 0 , this . _showMarkedAsFailingTests ) . forEach ( ( testRun , index ) => {
116
+ console . log ( `${ index + 1 } ) ${ testRun . test ( ) . fullName ( ) } (${ formatLocation ( testRun . test ( ) . location ( ) ) } )` ) ;
125
117
} ) ;
126
118
}
127
- if ( this . _showMarkedAsFailingTests < markedAsFailingTests . length ) {
119
+ if ( this . _showMarkedAsFailingTests < markedAsFailingRuns . length ) {
128
120
console . log ( '' ) ;
129
- console . log ( `... and ${ colors . yellow ( markedAsFailingTests . length - this . _showMarkedAsFailingTests ) } more marked as failing tests ...` ) ;
121
+ console . log ( `... and ${ colors . yellow ( markedAsFailingRuns . length - this . _showMarkedAsFailingTests ) } more marked as failing tests ...` ) ;
130
122
}
131
123
}
132
124
133
125
if ( this . _showSlowTests ) {
134
- const slowTests = this . _runner . passedTests ( ) . sort ( ( a , b ) => {
135
- const aDuration = a . endTimestamp - a . startTimestamp ;
136
- const bDuration = b . endTimestamp - b . startTimestamp ;
137
- return bDuration - aDuration ;
138
- } ) . slice ( 0 , this . _showSlowTests ) ;
126
+ const slowRuns = okRuns . sort ( ( a , b ) => b . duration ( ) - a . duration ( ) ) . slice ( 0 , this . _showSlowTests ) ;
139
127
console . log ( `\nSlowest tests:` ) ;
140
- for ( let i = 0 ; i < slowTests . length ; ++ i ) {
141
- const test = slowTests [ i ] ;
142
- const duration = test . endTimestamp - test . startTimestamp ;
143
- console . log ( ` (${ i + 1 } ) ${ colors . yellow ( ( duration / 1000 ) + 's' ) } - ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
128
+ for ( let i = 0 ; i < slowRuns . length ; ++ i ) {
129
+ const run = slowRuns [ i ] ;
130
+ console . log ( ` (${ i + 1 } ) ${ colors . yellow ( ( run . duration ( ) / 1000 ) + 's' ) } - ${ run . test ( ) . fullName ( ) } (${ formatLocation ( run . test ( ) . location ( ) ) } )` ) ;
144
131
}
145
132
}
146
133
147
- const tests = this . _runner . tests ( ) ;
148
- const executedTests = tests . filter ( test => test . result ) ;
149
- const okTestsLength = executedTests . length - failedTests . length - markedAsFailingTests . length - skippedTests . length ;
150
134
let summaryText = '' ;
151
- if ( failedTests . length || markedAsFailingTests . length ) {
152
- const summary = [ `ok - ${ colors . green ( okTestsLength ) } ` ] ;
153
- if ( failedTests . length )
154
- summary . push ( `failed - ${ colors . red ( failedTests . length ) } ` ) ;
155
- if ( markedAsFailingTests . length )
156
- summary . push ( `marked as failing - ${ colors . yellow ( markedAsFailingTests . length ) } ` ) ;
157
- if ( skippedTests . length )
158
- summary . push ( `skipped - ${ colors . yellow ( skippedTests . length ) } ` ) ;
135
+ if ( failedRuns . length || markedAsFailingRuns . length ) {
136
+ const summary = [ `ok - ${ colors . green ( okRuns . length ) } ` ] ;
137
+ if ( failedRuns . length )
138
+ summary . push ( `failed - ${ colors . red ( failedRuns . length ) } ` ) ;
139
+ if ( markedAsFailingRuns . length )
140
+ summary . push ( `marked as failing - ${ colors . yellow ( markedAsFailingRuns . length ) } ` ) ;
141
+ if ( skippedRuns . length )
142
+ summary . push ( `skipped - ${ colors . yellow ( skippedRuns . length ) } ` ) ;
159
143
summaryText = ` (${ summary . join ( ', ' ) } )` ;
160
144
}
161
145
162
- console . log ( `\nRan ${ executedTests . length } ${ summaryText } of ${ tests . length } test${ tests . length > 1 ? 's' : '' } ` ) ;
146
+ console . log ( `\nRan ${ executedRuns . length } ${ summaryText } of ${ runs . length } test${ runs . length > 1 ? 's' : '' } ` ) ;
163
147
const milliseconds = Date . now ( ) - this . _timestamp ;
164
148
const seconds = milliseconds / 1000 ;
165
149
console . log ( `Finished in ${ colors . yellow ( seconds ) } seconds` ) ;
166
150
}
167
151
168
- _onTestStarted ( test , workerId ) {
152
+ _onTestStarted ( testRun ) {
169
153
}
170
154
171
- _onTestFinished ( test , workerId ) {
155
+ _onTestFinished ( testRun ) {
172
156
if ( this . _verbose ) {
173
157
++ this . _testCounter ;
174
- this . _printVerboseTestResult ( this . _testCounter , test , workerId ) ;
158
+ this . _printVerboseTestRunResult ( this . _testCounter , testRun ) ;
175
159
} else {
176
- if ( test . result === 'ok' )
160
+ if ( testRun . result ( ) === 'ok' )
177
161
process . stdout . write ( colors . green ( '\u00B7' ) ) ;
178
- else if ( test . result === 'skipped' )
162
+ else if ( testRun . result ( ) === 'skipped' )
179
163
process . stdout . write ( colors . yellow ( '\u00B7' ) ) ;
180
- else if ( test . result === 'markedAsFailing' )
164
+ else if ( testRun . result ( ) === 'markedAsFailing' )
181
165
process . stdout . write ( colors . yellow ( '\u00D7' ) ) ;
182
- else if ( test . result === 'failed' )
166
+ else if ( testRun . result ( ) === 'failed' )
183
167
process . stdout . write ( colors . red ( 'F' ) ) ;
184
- else if ( test . result === 'crashed' )
168
+ else if ( testRun . result ( ) === 'crashed' )
185
169
process . stdout . write ( colors . red ( 'C' ) ) ;
186
- else if ( test . result === 'terminated' )
170
+ else if ( testRun . result ( ) === 'terminated' )
187
171
process . stdout . write ( colors . magenta ( '.' ) ) ;
188
- else if ( test . result === 'timedout' )
172
+ else if ( testRun . result ( ) === 'timedout' )
189
173
process . stdout . write ( colors . red ( 'T' ) ) ;
190
174
}
191
175
}
192
176
193
- _printVerboseTestResult ( resultIndex , test , workerId = undefined ) {
177
+ _printVerboseTestRunResult ( resultIndex , testRun ) {
178
+ const test = testRun . test ( ) ;
194
179
let prefix = `${ resultIndex } )` ;
195
- if ( this . _runner . parallel ( ) > 1 && workerId !== undefined )
196
- prefix += ' ' + colors . gray ( `[worker = ${ workerId } ]` ) ;
197
- if ( test . result === 'ok' ) {
180
+ if ( this . _runner . parallel ( ) > 1 )
181
+ prefix += ' ' + colors . gray ( `[worker = ${ testRun . workerId ( ) } ]` ) ;
182
+ if ( testRun . result ( ) === 'ok' ) {
198
183
console . log ( `${ prefix } ${ colors . green ( '[OK]' ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
199
- } else if ( test . result === 'terminated' ) {
184
+ } else if ( testRun . result ( ) === 'terminated' ) {
200
185
console . log ( `${ prefix } ${ colors . magenta ( '[TERMINATED]' ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
201
- } else if ( test . result === 'crashed' ) {
186
+ } else if ( testRun . result ( ) === 'crashed' ) {
202
187
console . log ( `${ prefix } ${ colors . red ( '[CRASHED]' ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
203
- } else if ( test . result === 'skipped' ) {
204
- } else if ( test . result === 'markedAsFailing' ) {
188
+ } else if ( testRun . result ( ) === 'skipped' ) {
189
+ } else if ( testRun . result ( ) === 'markedAsFailing' ) {
205
190
console . log ( `${ prefix } ${ colors . yellow ( '[MARKED AS FAILING]' ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
206
- } else if ( test . result === 'timedout' ) {
191
+ } else if ( testRun . result ( ) === 'timedout' ) {
207
192
console . log ( `${ prefix } ${ colors . red ( `[TIMEOUT ${ test . timeout ( ) } ms]` ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
208
- if ( test . output ) {
193
+ if ( testRun . output ) {
209
194
console . log ( ' Output:' ) ;
210
- for ( const line of test . output )
195
+ for ( const line of testRun . output )
211
196
console . log ( ' ' + line ) ;
212
197
}
213
- } else if ( test . result === 'failed' ) {
198
+ } else if ( testRun . result ( ) === 'failed' ) {
214
199
console . log ( `${ prefix } ${ colors . red ( '[FAIL]' ) } ${ test . fullName ( ) } (${ formatLocation ( test . location ( ) ) } )` ) ;
215
- if ( test . error instanceof MatchError ) {
216
- let lines = this . _filePathToLines . get ( test . error . location . filePath ) ;
200
+ if ( testRun . error ( ) instanceof MatchError ) {
201
+ let lines = this . _filePathToLines . get ( testRun . error ( ) . location . filePath ) ;
217
202
if ( ! lines ) {
218
203
try {
219
- lines = fs . readFileSync ( test . error . location . filePath , 'utf8' ) . split ( '\n' ) ;
204
+ lines = fs . readFileSync ( testRun . error ( ) . location . filePath , 'utf8' ) . split ( '\n' ) ;
220
205
} catch ( e ) {
221
206
lines = [ ] ;
222
207
}
223
- this . _filePathToLines . set ( test . error . location . filePath , lines ) ;
208
+ this . _filePathToLines . set ( testRun . error ( ) . location . filePath , lines ) ;
224
209
}
225
- const lineNumber = test . error . location . lineNumber ;
210
+ const lineNumber = testRun . error ( ) . location . lineNumber ;
226
211
if ( lineNumber < lines . length ) {
227
212
const lineNumberLength = ( lineNumber + 1 + '' ) . length ;
228
213
const FROM = Math . max ( test . location ( ) . lineNumber - 1 , lineNumber - 5 ) ;
229
214
const snippet = lines . slice ( FROM , lineNumber ) . map ( ( line , index ) => ` ${ ( FROM + index + 1 + '' ) . padStart ( lineNumberLength , ' ' ) } | ${ line } ` ) . join ( '\n' ) ;
230
- const pointer = ` ` + ' ' . repeat ( lineNumberLength ) + ' ' + '~' . repeat ( test . error . location . columnNumber - 1 ) + '^' ;
215
+ const pointer = ` ` + ' ' . repeat ( lineNumberLength ) + ' ' + '~' . repeat ( testRun . error ( ) . location . columnNumber - 1 ) + '^' ;
231
216
console . log ( '\n' + snippet + '\n' + colors . grey ( pointer ) + '\n' ) ;
232
217
}
233
- console . log ( padLines ( test . error . formatter ( ) , 4 ) ) ;
218
+ console . log ( padLines ( testRun . error ( ) . formatter ( ) , 4 ) ) ;
234
219
console . log ( '' ) ;
235
220
} else {
236
221
console . log ( ' Message:' ) ;
237
- let message = '' + ( test . error . message || test . error ) ;
238
- if ( test . error . stack && message . includes ( test . error . stack ) )
239
- message = message . substring ( 0 , message . indexOf ( test . error . stack ) ) ;
222
+ let message = '' + ( testRun . error ( ) . message || testRun . error ( ) ) ;
223
+ if ( testRun . error ( ) . stack && message . includes ( testRun . error ( ) . stack ) )
224
+ message = message . substring ( 0 , message . indexOf ( testRun . error ( ) . stack ) ) ;
240
225
if ( message )
241
226
console . log ( ` ${ colors . red ( message ) } ` ) ;
242
- if ( test . error . stack ) {
227
+ if ( testRun . error ( ) . stack ) {
243
228
console . log ( ' Stack:' ) ;
244
- let stack = test . error . stack ;
229
+ let stack = testRun . error ( ) . stack ;
245
230
// Highlight first test location, if any.
246
231
const match = stack . match ( new RegExp ( test . location ( ) . filePath + ':(\\d+):(\\d+)' ) ) ;
247
232
if ( match ) {
@@ -252,9 +237,9 @@ class Reporter {
252
237
console . log ( padLines ( stack , 4 ) ) ;
253
238
}
254
239
}
255
- if ( test . output ) {
240
+ if ( testRun . output ) {
256
241
console . log ( ' Output:' ) ;
257
- for ( const line of test . output )
242
+ for ( const line of testRun . output )
258
243
console . log ( ' ' + line ) ;
259
244
}
260
245
}
0 commit comments