11'use strict' ;
22
3- var path = require ( 'path' ) ,
3+ const path = require ( 'path' ) ;
4+ const chalk = require ( 'chalk' ) ;
5+ const fs = require ( 'fs-extra' ) ;
6+ const Promise = require ( 'bluebird' ) ;
47
5- Promise = require ( 'bluebird' ) ,
6- fs = require ( 'fs-extra' ) ,
7-
8- view = require ( './view' ) ,
9- ViewModel = require ( './view-model' ) ,
10- lib = require ( './lib' ) ,
11- chalk = require ( 'chalk' ) ,
12- logger = require ( '../../utils' ) . logger ,
13-
14- Events = require ( '../../constants/events' ) ;
8+ const lib = require ( './lib' ) ;
9+ const view = require ( './view' ) ;
10+ const ViewModel = require ( './view-model' ) ;
11+ const logger = require ( '../../utils' ) . logger ;
12+ const Events = require ( '../../constants/events' ) ;
1513
1614/**
1715 * @param {String } srcPath
@@ -20,7 +18,7 @@ var path = require('path'),
2018 */
2119function copyImage ( srcPath , destPath ) {
2220 return makeDirFor ( destPath )
23- . then ( fs . copyAsync . bind ( fs , srcPath , destPath ) ) ;
21+ . then ( ( ) => fs . copyAsync ( srcPath , destPath ) ) ;
2422}
2523
2624/**
@@ -30,7 +28,7 @@ function copyImage(srcPath, destPath) {
3028 */
3129function saveDiff ( result , destPath ) {
3230 return makeDirFor ( destPath )
33- . then ( result . saveDiffTo . bind ( result , destPath ) ) ;
31+ . then ( ( ) => result . saveDiffTo ( destPath ) ) ;
3432}
3533
3634/**
@@ -46,20 +44,16 @@ function prepareViewData(runner) {
4644
4745 runner . on ( Events . SKIP_STATE , model . addSkipped . bind ( model ) ) ;
4846
49- runner . on ( Events . TEST_RESULT , function ( r ) {
50- if ( r . equal ) {
51- model . addSuccess ( r ) ;
52- } else {
53- model . addFail ( r ) ;
54- }
47+ runner . on ( Events . TEST_RESULT , ( result ) => {
48+ result . equal ? model . addSuccess ( result ) : model . addFail ( result ) ;
5549 } ) ;
5650
5751 runner . on ( Events . RETRY , model . addRetry . bind ( model ) ) ;
5852
5953 runner . on ( Events . ERROR , model . addError . bind ( model ) ) ;
6054 runner . on ( Events . WARNING , model . addWarning . bind ( model ) ) ;
6155
62- runner . on ( Events . END , function ( ) {
56+ runner . on ( Events . END , ( ) => {
6357 resolve ( model . getResult ( ) ) ;
6458 } ) ;
6559 } ) ;
@@ -77,11 +71,18 @@ function logPathToHtmlReport() {
7771
7872function prepareImages ( runner ) {
7973 function handleTestResultEvent_ ( testResult ) {
80- return Promise . all ( [
81- copyImage ( testResult . currentPath , lib . currentAbsolutePath ( testResult ) ) ,
82- copyImage ( testResult . referencePath , lib . referenceAbsolutePath ( testResult ) ) ,
83- testResult . equal || saveDiff ( testResult , lib . diffAbsolutePath ( testResult ) )
84- ] ) ;
74+ let actions = [
75+ copyImage ( testResult . currentPath , lib . currentAbsolutePath ( testResult ) )
76+ ] ;
77+
78+ if ( ! testResult . equal ) {
79+ actions . push (
80+ copyImage ( testResult . referencePath , lib . referenceAbsolutePath ( testResult ) ) ,
81+ saveDiff ( testResult , lib . diffAbsolutePath ( testResult ) )
82+ ) ;
83+ }
84+
85+ return Promise . all ( actions ) ;
8586 }
8687
8788 function handleErrorEvent_ ( testResult ) {
@@ -93,47 +94,40 @@ function prepareImages(runner) {
9394 return new Promise ( ( resolve , reject ) => {
9495 let queue = Promise . resolve ( true ) ;
9596
96- runner . on ( Events . WARNING , function ( testResult ) {
97- queue = queue . then ( function ( ) {
97+ runner . on ( Events . WARNING , ( testResult ) => {
98+ queue = queue . then ( ( ) => {
9899 return copyImage ( testResult . currentPath , lib . currentAbsolutePath ( testResult ) ) ;
99100 } ) ;
100101 } ) ;
101102
102- runner . on ( Events . ERROR , function ( testResult ) {
103- queue = queue . then ( function ( ) {
104- return handleErrorEvent_ ( testResult ) ;
105- } ) ;
103+ runner . on ( Events . ERROR , ( testResult ) => {
104+ queue = queue . then ( ( ) => handleErrorEvent_ ( testResult ) ) ;
106105 } ) ;
107106
108- runner . on ( Events . RETRY , function ( testResult ) {
109- queue = queue . then ( function ( ) {
107+ runner . on ( Events . RETRY , ( testResult ) => {
108+ queue = queue . then ( ( ) => {
110109 return testResult . hasOwnProperty ( 'equal' )
111110 ? handleTestResultEvent_ ( testResult )
112111 : handleErrorEvent_ ( testResult ) ;
113112 } ) ;
114113 } ) ;
115114
116115 runner . on ( Events . TEST_RESULT , function ( testResult ) {
117- queue = queue . then ( function ( ) {
118- return handleTestResultEvent_ ( testResult ) ;
119- } ) ;
116+ queue = queue . then ( ( ) => handleTestResultEvent_ ( testResult ) ) ;
120117 } ) ;
121118
122- runner . on ( Events . END , function ( ) {
123- logPathToHtmlReport ( ) ;
124-
119+ runner . on ( Events . END , ( ) => {
125120 queue . then ( resolve , reject ) ;
126121 } ) ;
127122 } ) ;
128123}
129124
130- module . exports = function htmlReporter ( tester ) {
131- Promise . all ( [
132- prepareViewData ( tester ) ,
133- prepareImages ( tester )
134- ] )
125+ module . exports = function htmlReporter ( runner ) {
126+ const generateReportPromise = Promise . all ( [ prepareViewData ( runner ) , prepareImages ( runner ) ] )
135127 . spread ( view . createHtml )
136128 . then ( view . save )
137- . catch ( logError )
138- . done ( ) ;
129+ . then ( logPathToHtmlReport )
130+ . catch ( logError ) ;
131+
132+ runner . on ( Events . END_RUNNER , ( ) => generateReportPromise . thenReturn ( ) ) ;
139133} ;
0 commit comments