@@ -10,25 +10,13 @@ declare global {
10
10
screenshotConfig ?: Partial < Cypress . ScreenshotDefaultsOptions > ;
11
11
diffConfig ?: Parameters < typeof pixelmatch > [ 5 ] ;
12
12
updateImages ?: boolean ;
13
+ /**
14
+ * @deprecated since version 3.0, use imagesPath instead
15
+ */
13
16
imagesDir ?: string ;
17
+ imagesPath ?: string ;
14
18
maxDiffThreshold ?: number ;
15
19
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 ;
32
20
} ;
33
21
34
22
interface Chainable < Subject > {
@@ -37,7 +25,7 @@ declare global {
37
25
* @memberof Cypress.Chainable
38
26
* @example cy.get('.my-element').matchImage();
39
27
*/
40
- matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < MatchImageReturn > ;
28
+ matchImage ( options ?: Cypress . MatchImageOptions ) : Chainable < Subject > ;
41
29
}
42
30
}
43
31
}
@@ -50,41 +38,60 @@ const constructCypressError = (log: Cypress.Log, err: Error) => {
50
38
return err ;
51
39
} ;
52
40
53
- export const getConfig = ( options : Cypress . MatchImageOptions ) => ( {
54
- scaleFactor :
55
- Cypress . env ( "pluginVisualRegressionForceDeviceScaleFactor" ) === false
56
- ? 1
57
- : 1 / window . devicePixelRatio ,
58
- updateImages :
59
- options . updateImages ||
60
- ( Cypress . env ( "pluginVisualRegressionUpdateImages" ) as
61
- | boolean
62
- | undefined ) ||
63
- false ,
64
- imagesDir :
41
+ const getImagesDir = ( options : Cypress . MatchImageOptions ) => {
42
+ const imagesDir =
65
43
options . imagesDir ||
66
- ( Cypress . env ( "pluginVisualRegressionImagesDir" ) as string | undefined ) ||
67
- "__image_snapshots__" ,
68
- maxDiffThreshold :
69
- options . maxDiffThreshold ||
70
- ( Cypress . env ( "pluginVisualRegressionMaxDiffThreshold" ) as
71
- | number
72
- | undefined ) ||
73
- 0.01 ,
74
- diffConfig :
75
- options . diffConfig ||
76
- ( Cypress . env ( "pluginVisualRegressionDiffConfig" ) as
77
- | Parameters < typeof pixelmatch > [ 5 ]
78
- | undefined ) ||
79
- { } ,
80
- screenshotConfig :
81
- options . screenshotConfig ||
82
- ( Cypress . env ( "pluginVisualRegressionScreenshotConfig" ) as
83
- | Partial < Cypress . ScreenshotDefaultsOptions >
84
- | undefined ) ||
85
- { } ,
86
- matchAgainstPath : options . matchAgainstPath || undefined ,
87
- } ) ;
44
+ ( Cypress . env ( "pluginVisualRegressionImagesDir" ) as string | undefined ) ;
45
+
46
+ // TODO: remove in 4.0.0
47
+ if ( imagesDir ) {
48
+ console . warn (
49
+ "@frsource/cypress-plugin-visual-regression-diff] `imagesDir` option is deprecated, use `imagesPath` instead (https://github.com/FRSOURCE/cypress-plugin-visual-regression-diff#configuration)"
50
+ ) ;
51
+ }
52
+
53
+ return imagesDir ;
54
+ } ;
55
+
56
+ export const getConfig = ( options : Cypress . MatchImageOptions ) => {
57
+ const imagesDir = getImagesDir ( options ) ;
58
+
59
+ return {
60
+ scaleFactor :
61
+ Cypress . env ( "pluginVisualRegressionForceDeviceScaleFactor" ) === false
62
+ ? 1
63
+ : 1 / window . devicePixelRatio ,
64
+ updateImages :
65
+ options . updateImages ||
66
+ ( Cypress . env ( "pluginVisualRegressionUpdateImages" ) as
67
+ | boolean
68
+ | undefined ) ||
69
+ false ,
70
+ imagesPath :
71
+ ( imagesDir && `{spec_path}/${ imagesDir } ` ) ||
72
+ options . imagesPath ||
73
+ ( Cypress . env ( "pluginVisualRegressionImagesPath" ) as string | undefined ) ||
74
+ "{spec_path}/__image_snapshots__" ,
75
+ maxDiffThreshold :
76
+ options . maxDiffThreshold ||
77
+ ( Cypress . env ( "pluginVisualRegressionMaxDiffThreshold" ) as
78
+ | number
79
+ | undefined ) ||
80
+ 0.01 ,
81
+ diffConfig :
82
+ options . diffConfig ||
83
+ ( Cypress . env ( "pluginVisualRegressionDiffConfig" ) as
84
+ | Parameters < typeof pixelmatch > [ 5 ]
85
+ | undefined ) ||
86
+ { } ,
87
+ screenshotConfig :
88
+ options . screenshotConfig ||
89
+ ( Cypress . env ( "pluginVisualRegressionScreenshotConfig" ) as
90
+ | Partial < Cypress . ScreenshotDefaultsOptions >
91
+ | undefined ) ||
92
+ { } ,
93
+ } ;
94
+ } ;
88
95
89
96
Cypress . Commands . add (
90
97
"matchImage" ,
@@ -96,11 +103,10 @@ Cypress.Commands.add(
96
103
const {
97
104
scaleFactor,
98
105
updateImages,
99
- imagesDir ,
106
+ imagesPath ,
100
107
maxDiffThreshold,
101
108
diffConfig,
102
109
screenshotConfig,
103
- matchAgainstPath,
104
110
} = getConfig ( options ) ;
105
111
106
112
return cy
@@ -110,7 +116,7 @@ Cypress.Commands.add(
110
116
{
111
117
titleFromOptions :
112
118
options . title || Cypress . currentTest . titlePath . join ( " " ) ,
113
- imagesDir ,
119
+ imagesPath ,
114
120
specPath : Cypress . spec . relative ,
115
121
} ,
116
122
{ log : false }
@@ -120,7 +126,7 @@ Cypress.Commands.add(
120
126
title = titleFromTask ;
121
127
let imgPath : string ;
122
128
return ( $el ? cy . wrap ( $el ) : cy )
123
- . screenshot ( screenshotPath as string , {
129
+ . screenshot ( screenshotPath , {
124
130
...screenshotConfig ,
125
131
onAfterScreenshot ( el , props ) {
126
132
imgPath = props . path ;
@@ -130,14 +136,14 @@ Cypress.Commands.add(
130
136
} )
131
137
. then ( ( ) => imgPath ) ;
132
138
} )
133
- . then ( ( imgPath ) => {
134
- return cy
139
+ . then ( ( imgPath ) =>
140
+ cy
135
141
. task < CompareImagesTaskReturn > (
136
142
TASK . compareImages ,
137
143
{
138
144
scaleFactor,
139
145
imgNew : imgPath ,
140
- imgOld : matchAgainstPath || imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
146
+ imgOld : imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
141
147
updateImages,
142
148
maxDiffThreshold,
143
149
diffConfig,
@@ -148,7 +154,7 @@ Cypress.Commands.add(
148
154
res,
149
155
imgPath,
150
156
} ) )
151
- } )
157
+ )
152
158
. then ( ( { res, imgPath } ) => {
153
159
const log = Cypress . log ( {
154
160
name : "log" ,
@@ -185,19 +191,6 @@ Cypress.Commands.add(
185
191
log . set ( "consoleProps" , ( ) => res ) ;
186
192
throw constructCypressError ( log , new Error ( res . message ) ) ;
187
193
}
188
-
189
- return {
190
- diffValue : res . imgDiff ,
191
- imgNewPath : imgPath ,
192
- imgPath : imgPath . replace ( FILE_SUFFIX . actual , "" ) ,
193
- imgDiffPath : imgPath . replace ( FILE_SUFFIX . actual , FILE_SUFFIX . diff ) ,
194
- imgNewBase64 : res . imgNewBase64 ,
195
- imgBase64 : res . imgOldBase64 ,
196
- imgDiffBase64 : res . imgDiffBase64 ,
197
- imgNew : typeof res . imgNewBase64 === 'string' ? Cypress . Buffer . from ( res . imgNewBase64 , 'base64' ) : undefined ,
198
- img : typeof res . imgOldBase64 === 'string' ? Cypress . Buffer . from ( res . imgOldBase64 , 'base64' ) : undefined ,
199
- imgDiff : typeof res . imgDiffBase64 === 'string' ? Cypress . Buffer . from ( res . imgDiffBase64 , 'base64' ) : undefined ,
200
- }
201
194
} ) ;
202
195
}
203
196
) ;
0 commit comments