@@ -6,30 +6,39 @@ const utils = require('./utils');
66const NoRefImageError = require ( '../../errors/no-ref-image-error' ) ;
77const { temp} = require ( 'gemini-core' ) ;
88
9- const throwNoRefError = ( referencePath , capture ) => {
10- const currentPath = temp . path ( { suffix : '.png' } ) ;
11- return capture . image . save ( currentPath )
12- . then ( ( ) => Promise . reject ( new NoRefImageError ( referencePath , currentPath ) ) ) ;
9+ const throwNoRefError = ( refImg , capture ) => {
10+ const currImg = { path : temp . path ( { suffix : '.png' } ) , size : capture . image . getSize ( ) } ;
11+
12+ return capture . image . save ( currImg . path )
13+ . then ( ( ) => Promise . reject ( new NoRefImageError ( refImg , currImg ) ) ) ;
1314} ;
14- const notUpdated = ( referencePath ) => ( { imagePath : referencePath , updated : false } ) ;
15+ const notUpdated = ( refImg ) => ( { refImg, updated : false } ) ;
16+
17+ const saveRef = ( refImg , capture ) => {
18+ refImg . size = capture . image . getSize ( ) ;
1519
16- const saveRef = ( referencePath , capture ) => {
17- return utils . saveRef ( referencePath , capture )
18- . then ( ( updated ) => ( { imagePath : referencePath , updated} ) ) ;
20+ return utils . saveRef ( refImg . path , capture )
21+ . then ( ( updated ) => ( { refImg, updated} ) ) ;
1922} ;
2023
21- const updateRef = ( referencePath , currentPath ) => {
22- return utils . copyImg ( currentPath , referencePath )
23- . then ( ( updated ) => ( { imagePath : referencePath , updated} ) ) ;
24+ const updateRef = ( refImg , currImg ) => {
25+ return utils . copyImg ( currImg . path , refImg . path )
26+ . then ( ( updated ) => {
27+ if ( updated ) {
28+ refImg . size = currImg . size ;
29+ }
30+
31+ return { refImg, updated} ;
32+ } ) ;
2433} ;
2534
2635exports . create = ( type ) => {
2736 if ( type === 'tester' ) {
2837 return CaptureProcessor . create ( )
2938 . onReference ( )
3039 . onNoReference ( throwNoRefError )
31- . onEqual ( ( referencePath , currentPath ) => ( { referencePath , currentPath , equal : true } ) )
32- . onDiff ( ( referencePath , currentPath ) => ( { referencePath , currentPath , equal : false } ) ) ;
40+ . onEqual ( ( refImg , currImg ) => ( { refImg , currImg , equal : true } ) )
41+ . onDiff ( ( refImg , currImg ) => ( { refImg , currImg , equal : false } ) ) ;
3342 }
3443
3544 if ( type === 'new-updater' ) {
0 commit comments