@@ -13,6 +13,22 @@ declare global {
1313 imagesDir ?: string ;
1414 maxDiffThreshold ?: number ;
1515 title ?: string ;
16+ matchAgainstPath ?: string ;
17+ // IDEA: to be implemented if support for files NOT from filesystem needed
18+ // matchAgainst?: string | Buffer;
19+ } ;
20+
21+ type MatchImageReturn = {
22+ diffValue : number | undefined ;
23+ imgNewPath : string ;
24+ imgPath : string ;
25+ imgDiffPath : string ;
26+ imgNewBase64 : string | undefined ;
27+ imgBase64 : string | undefined ;
28+ imgDiffBase64 : string | undefined ;
29+ imgNew : InstanceType < Cypress [ 'Buffer' ] > | undefined ;
30+ img : InstanceType < Cypress [ 'Buffer' ] > | undefined ;
31+ imgDiff : InstanceType < Cypress [ 'Buffer' ] > | undefined ;
1632 } ;
1733
1834 interface Chainable < Subject > {
@@ -21,7 +37,7 @@ declare global {
2137 * @memberof Cypress.Chainable
2238 * @example cy.get('.my-element').matchImage();
2339 */
24- matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < Subject > ;
40+ matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < MatchImageReturn > ;
2541 }
2642 }
2743}
@@ -69,6 +85,7 @@ export const getConfig = (options: Cypress.MatchImageOptions) => ({
6985 | Partial < Cypress . ScreenshotDefaultsOptions >
7086 | undefined ) ||
7187 { } ,
88+ matchAgainstPath : options . matchAgainstPath || undefined ,
7289} ) ;
7390
7491Cypress . Commands . add (
@@ -88,6 +105,7 @@ Cypress.Commands.add(
88105 maxDiffThreshold,
89106 diffConfig,
90107 screenshotConfig,
108+ matchAgainstPath,
91109 } = getConfig ( options ) ;
92110
93111 return cy
@@ -115,14 +133,14 @@ Cypress.Commands.add(
115133 } )
116134 . then ( ( ) => imgPath ) ;
117135 } )
118- . then ( ( imgPath ) =>
119- cy
136+ . then ( ( imgPath ) => {
137+ return cy
120138 . task < CompareImagesTaskReturn > (
121139 TASK . compareImages ,
122140 {
123141 scaleFactor,
124142 imgNew : imgPath ,
125- imgOld : imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
143+ imgOld : matchAgainstPath || imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
126144 updateImages,
127145 maxDiffThreshold,
128146 diffConfig,
@@ -133,7 +151,7 @@ Cypress.Commands.add(
133151 res,
134152 imgPath,
135153 } ) )
136- )
154+ } )
137155 . then ( ( { res, imgPath } ) => {
138156 const log = Cypress . log ( {
139157 name : "log" ,
@@ -170,6 +188,19 @@ Cypress.Commands.add(
170188 log . set ( "consoleProps" , ( ) => res ) ;
171189 throw constructCypressError ( log , new Error ( res . message ) ) ;
172190 }
191+
192+ return {
193+ diffValue : res . imgDiff ,
194+ imgNewPath : imgPath ,
195+ imgPath : imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
196+ imgDiffPath : imgPath . replace ( FILE_SUFFIX . actual , FILE_SUFFIX . diff ) ,
197+ imgNewBase64 : res . imgNewBase64 ,
198+ imgBase64 : res . imgOldBase64 ,
199+ imgDiffBase64 : res . imgDiffBase64 ,
200+ imgNew : typeof res . imgNewBase64 === 'string' ? Cypress . Buffer . from ( res . imgNewBase64 , 'base64' ) : undefined ,
201+ img : typeof res . imgOldBase64 === 'string' ? Cypress . Buffer . from ( res . imgOldBase64 , 'base64' ) : undefined ,
202+ imgDiff : typeof res . imgDiffBase64 === 'string' ? Cypress . Buffer . from ( res . imgDiffBase64 , 'base64' ) : undefined ,
203+ }
173204 } ) ;
174205 }
175206) ;
0 commit comments