@@ -101,36 +101,43 @@ module.exports = class TestAdapter {
101101 return [ id . toString ( ) , browserId , stateName ] . join ( '/' ) ;
102102 }
103103
104- _getExpectedPath ( stateName , status ) {
104+ _getExpectedPath ( stateName , status , cacheExpectedPaths ) {
105105 const key = this . _getExpectedKey ( stateName ) ;
106106
107107 if ( status === UPDATED ) {
108108 const expectedPath = utils . getReferencePath ( this , stateName ) ;
109- globalCacheExpectedPaths . set ( key , expectedPath ) ;
109+ cacheExpectedPaths . set ( key , expectedPath ) ;
110110
111- return expectedPath ;
111+ return { path : expectedPath , reused : false } ;
112112 }
113113
114- if ( globalCacheExpectedPaths . has ( key ) ) {
115- return globalCacheExpectedPaths . get ( key ) ;
114+ if ( cacheExpectedPaths . has ( key ) ) {
115+ return { path : cacheExpectedPaths . get ( key ) , reused : true } ;
116116 }
117117
118118 const imageInfo = this . _getLastImageInfoFromDB ( stateName ) ;
119- const expectedPath = imageInfo && imageInfo . expectedImg
120- ? imageInfo . expectedImg . path
121- : utils . getReferencePath ( this , stateName ) ;
122119
123- globalCacheExpectedPaths . set ( key , expectedPath ) ;
120+ if ( imageInfo && imageInfo . expectedImg ) {
121+ const expectedPath = imageInfo . expectedImg . path ;
124122
125- return expectedPath ;
123+ cacheExpectedPaths . set ( key , expectedPath ) ;
124+
125+ return { path : expectedPath , reused : true } ;
126+ }
127+
128+ const expectedPath = utils . getReferencePath ( this , stateName ) ;
129+
130+ cacheExpectedPaths . set ( key , expectedPath ) ;
131+
132+ return { path : expectedPath , reused : false } ;
126133 }
127134
128135 getImagesFor ( status , stateName ) {
129136 const refImg = this . getRefImg ( stateName ) ;
130137 const currImg = this . getCurrImg ( stateName ) ;
131138 const errImg = this . getErrImg ( ) ;
132139
133- const refPath = this . _getExpectedPath ( stateName , status ) ;
140+ const { path : refPath } = this . _getExpectedPath ( stateName , status , globalCacheExpectedPaths ) ;
134141 const currPath = utils . getCurrentPath ( this , stateName ) ;
135142 const diffPath = utils . getDiffPath ( this , stateName ) ;
136143
@@ -373,10 +380,10 @@ module.exports = class TestAdapter {
373380 await fs . writeFile ( detailsFilePath , detailsData ) ;
374381 }
375382
376- async saveTestImages ( reportPath , workers ) {
383+ async saveTestImages ( reportPath , workers , cacheExpectedPaths = globalCacheExpectedPaths ) {
377384 const result = await Promise . all ( this . assertViewResults . map ( async ( assertResult ) => {
378385 const { stateName} = assertResult ;
379- const destRefPath = this . _getExpectedPath ( stateName ) ;
386+ const { path : destRefPath , reused : reusedReference } = this . _getExpectedPath ( stateName , undefined , cacheExpectedPaths ) ;
380387 const srcRefPath = this . getRefImg ( stateName ) . path ;
381388
382389 const destCurrPath = utils . getCurrentPath ( this , stateName ) ;
@@ -396,8 +403,11 @@ module.exports = class TestAdapter {
396403 actions . push (
397404 this . _saveImg ( srcCurrPath , destCurrPath , reportPath ) ,
398405 this . _saveImg ( srcDiffPath , dstCurrPath , reportPath ) ,
399- this . _saveImg ( srcRefPath , destRefPath , reportPath )
400406 ) ;
407+
408+ if ( ! reusedReference ) {
409+ actions . push ( this . _saveImg ( srcRefPath , destRefPath , reportPath ) ) ;
410+ }
401411 }
402412
403413 if ( this . isNoRefImageError ( assertResult ) ) {
0 commit comments