@@ -59,6 +59,11 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
5959 if ( ! actualBuffer || ! ( actualBuffer instanceof Buffer ) )
6060 return { errorMessage : 'Actual result should be a Buffer.' } ;
6161 validateBuffer ( expectedBuffer , mimeType ) ;
62+ const comparator = options . comparator ?? 'pixelmatch' ;
63+ if ( comparator !== 'pixelmatch' && comparator !== 'ssim-cie94' )
64+ throw new Error ( `Configuration specifies unknown comparator "${ options . comparator } "` ) ;
65+ if ( actualBuffer . equals ( expectedBuffer ) )
66+ return null ;
6267
6368 const decode = ( buffer : Buffer ) : ImageData => {
6469 if ( mimeType === 'image/png' )
@@ -69,6 +74,8 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
6974 } ;
7075 let actual : ImageData = decode ( actualBuffer ) ;
7176 let expected : ImageData = decode ( expectedBuffer ) ;
77+ if ( actual . width === expected . width && actual . height === expected . height && actual . data . equals ( expected . data ) )
78+ return null ;
7279 const size = { width : Math . max ( expected . width , actual . width ) , height : Math . max ( expected . height , actual . height ) } ;
7380 let sizesMismatchError = '' ;
7481 if ( expected . width !== actual . width || expected . height !== actual . height ) {
@@ -78,18 +85,16 @@ function compareImages(mimeType: string, actualBuffer: Buffer | string, expected
7885 }
7986 const diff = new PNG ( { width : size . width , height : size . height } ) ;
8087 let count ;
81- if ( options . comparator === 'ssim-cie94' ) {
88+ if ( comparator === 'ssim-cie94' ) {
8289 count = compare ( expected . data , actual . data , diff . data , size . width , size . height , {
8390 // All ΔE* formulae are originally designed to have the difference of 1.0 stand for a "just noticeable difference" (JND).
8491 // See https://en.wikipedia.org/wiki/Color_difference#CIELAB_%CE%94E*
8592 maxColorDeltaE94 : 1.0 ,
8693 } ) ;
87- } else if ( ( options . comparator ?? 'pixelmatch' ) === 'pixelmatch' ) {
94+ } else {
8895 count = pixelmatch ( expected . data , actual . data , diff . data , size . width , size . height , {
8996 threshold : options . threshold ?? 0.2 ,
9097 } ) ;
91- } else {
92- throw new Error ( `Configuration specifies unknown comparator "${ options . comparator } "` ) ;
9398 }
9499
95100 const maxDiffPixels1 = options . maxDiffPixels ;
0 commit comments