1 |
|
2 |
|
3 |
|
4 | const { VerboseReporter } = require( '@jest/reporters' );
|
5 |
|
6 | module.exports = class TravisFoldPassesReporter extends VerboseReporter {
|
7 | constructor( ...args ) {
|
8 | super( ...args );
|
9 | this.foldedTestResults = [];
|
10 | }
|
11 |
|
12 | flushFoldedTestResults() {
|
13 | if ( ! this.foldedTestResults.length ) {
|
14 | return;
|
15 | }
|
16 |
|
17 | this.log( 'travis_fold:start:TravisFoldPassesReporter' );
|
18 | this.log(
|
19 | `...${ this.foldedTestResults.length } passing test${
|
20 | this.foldedTestResults.length === 1 ? '' : 's'
|
21 | }.`
|
22 | );
|
23 | this.foldedTestResults.forEach( ( args ) => super.onTestResult( ...args ) );
|
24 | this.log( 'travis_fold:end:TravisFoldPassesReporter' );
|
25 | this.foldedTestResults = [];
|
26 | }
|
27 |
|
28 | onTestResult( ...args ) {
|
29 | const testResult = args[ 1 ];
|
30 | if ( testResult.numFailingTests === 0 && ! testResult.failureMessage ) {
|
31 | this.foldedTestResults.push( args );
|
32 | } else {
|
33 | this.flushFoldedTestResults();
|
34 | super.onTestResult( ...args );
|
35 | }
|
36 | }
|
37 |
|
38 | onRunComplete( ...args ) {
|
39 | this.flushFoldedTestResults();
|
40 | super.onRunComplete( ...args );
|
41 | }
|
42 | };
|