@@ -13,6 +13,22 @@ declare global {
13
13
imagesDir ?: string ;
14
14
maxDiffThreshold ?: number ;
15
15
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 ;
16
32
} ;
17
33
18
34
interface Chainable < Subject > {
@@ -21,7 +37,7 @@ declare global {
21
37
* @memberof Cypress.Chainable
22
38
* @example cy.get('.my-element').matchImage();
23
39
*/
24
- matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < Subject > ;
40
+ matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < MatchImageReturn > ;
25
41
}
26
42
}
27
43
}
@@ -69,6 +85,7 @@ export const getConfig = (options: Cypress.MatchImageOptions) => ({
69
85
| Partial < Cypress . ScreenshotDefaultsOptions >
70
86
| undefined ) ||
71
87
{ } ,
88
+ matchAgainstPath : options . matchAgainstPath || undefined ,
72
89
} ) ;
73
90
74
91
Cypress . Commands . add (
@@ -88,6 +105,7 @@ Cypress.Commands.add(
88
105
maxDiffThreshold,
89
106
diffConfig,
90
107
screenshotConfig,
108
+ matchAgainstPath,
91
109
} = getConfig ( options ) ;
92
110
93
111
return cy
@@ -115,14 +133,14 @@ Cypress.Commands.add(
115
133
} )
116
134
. then ( ( ) => imgPath ) ;
117
135
} )
118
- . then ( ( imgPath ) =>
119
- cy
136
+ . then ( ( imgPath ) => {
137
+ return cy
120
138
. task < CompareImagesTaskReturn > (
121
139
TASK . compareImages ,
122
140
{
123
141
scaleFactor,
124
142
imgNew : imgPath ,
125
- imgOld : imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
143
+ imgOld : matchAgainstPath || imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
126
144
updateImages,
127
145
maxDiffThreshold,
128
146
diffConfig,
@@ -133,7 +151,7 @@ Cypress.Commands.add(
133
151
res,
134
152
imgPath,
135
153
} ) )
136
- )
154
+ } )
137
155
. then ( ( { res, imgPath } ) => {
138
156
const log = Cypress . log ( {
139
157
name : "log" ,
@@ -170,6 +188,19 @@ Cypress.Commands.add(
170
188
log . set ( "consoleProps" , ( ) => res ) ;
171
189
throw constructCypressError ( log , new Error ( res . message ) ) ;
172
190
}
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
+ }
173
204
} ) ;
174
205
}
175
206
) ;
0 commit comments