@@ -48,6 +48,7 @@ describe("getScreenshotPathInfoTask", () => {
48
48
titleFromOptions : "some-title-withśpęćiał人物" ,
49
49
imagesPath : "nested/images/dir" ,
50
50
specPath,
51
+ currentRetryNumber : 0 ,
51
52
} )
52
53
) . toEqual ( {
53
54
screenshotPath :
@@ -62,6 +63,7 @@ describe("getScreenshotPathInfoTask", () => {
62
63
titleFromOptions : "some-title" ,
63
64
imagesPath : "{spec_path}/images/dir" ,
64
65
specPath,
66
+ currentRetryNumber : 0 ,
65
67
} )
66
68
) . toEqual ( {
67
69
screenshotPath :
@@ -76,6 +78,7 @@ describe("getScreenshotPathInfoTask", () => {
76
78
titleFromOptions : "some-title" ,
77
79
imagesPath : "/images/dir" ,
78
80
specPath,
81
+ currentRetryNumber : 0 ,
79
82
} )
80
83
) . toEqual ( {
81
84
screenshotPath :
@@ -88,6 +91,7 @@ describe("getScreenshotPathInfoTask", () => {
88
91
titleFromOptions : "some-title" ,
89
92
imagesPath : "C:/images/dir" ,
90
93
specPath,
94
+ currentRetryNumber : 0 ,
91
95
} )
92
96
) . toEqual ( {
93
97
screenshotPath :
@@ -104,6 +108,7 @@ describe("cleanupImagesTask", () => {
104
108
titleFromOptions : "some-file" ,
105
109
imagesPath : "images" ,
106
110
specPath : "some/spec/path" ,
111
+ currentRetryNumber : 0 ,
107
112
} ) ;
108
113
return path . join (
109
114
projectRoot ,
@@ -113,34 +118,56 @@ describe("cleanupImagesTask", () => {
113
118
) ;
114
119
} ;
115
120
116
- it ( "does not remove used screenshot" , async ( ) => {
117
- const { path : projectRoot } = await dir ( ) ;
118
- const screenshotPath = await writeTmpFixture (
119
- await generateUsedScreenshotPath ( projectRoot ) ,
120
- oldImgFixture
121
- ) ;
121
+ describe ( 'when testing type does not match' , ( ) => {
122
+ it ( "does not remove unused screenshot" , async ( ) => {
123
+ const { path : projectRoot } = await dir ( ) ;
124
+ const screenshotPath = await writeTmpFixture (
125
+ path . join ( projectRoot , "some-file-2 #0.png" ) ,
126
+ oldImgFixture
127
+ ) ;
122
128
123
- cleanupImagesTask ( {
124
- projectRoot,
125
- env : { pluginVisualRegressionCleanupUnusedImages : true } ,
126
- } as unknown as Cypress . PluginConfigOptions ) ;
129
+ cleanupImagesTask ( {
130
+ projectRoot,
131
+ env : { pluginVisualRegressionCleanupUnusedImages : true } ,
132
+ testingType : 'component' ,
133
+ } as unknown as Cypress . PluginConfigOptions ) ;
127
134
128
- expect ( existsSync ( screenshotPath ) ) . toBe ( true ) ;
135
+ expect ( existsSync ( screenshotPath ) ) . toBe ( true ) ;
136
+ } ) ;
129
137
} ) ;
130
138
131
- it ( "removes unused screenshot" , async ( ) => {
132
- const { path : projectRoot } = await dir ( ) ;
133
- const screenshotPath = await writeTmpFixture (
134
- path . join ( projectRoot , "some-file-2 #0.png" ) ,
135
- oldImgFixture
136
- ) ;
139
+ describe ( 'when testing type matches' , ( ) => {
140
+ it ( "does not remove used screenshot" , async ( ) => {
141
+ const { path : projectRoot } = await dir ( ) ;
142
+ const screenshotPath = await writeTmpFixture (
143
+ await generateUsedScreenshotPath ( projectRoot ) ,
144
+ oldImgFixture
145
+ ) ;
137
146
138
- cleanupImagesTask ( {
139
- projectRoot,
140
- env : { pluginVisualRegressionCleanupUnusedImages : true } ,
141
- } as unknown as Cypress . PluginConfigOptions ) ;
147
+ cleanupImagesTask ( {
148
+ projectRoot,
149
+ env : { pluginVisualRegressionCleanupUnusedImages : true } ,
150
+ testingType : 'e2e' ,
151
+ } as unknown as Cypress . PluginConfigOptions ) ;
142
152
143
- expect ( existsSync ( screenshotPath ) ) . toBe ( false ) ;
153
+ expect ( existsSync ( screenshotPath ) ) . toBe ( true ) ;
154
+ } ) ;
155
+
156
+ it ( "removes unused screenshot" , async ( ) => {
157
+ const { path : projectRoot } = await dir ( ) ;
158
+ const screenshotPath = await writeTmpFixture (
159
+ path . join ( projectRoot , "some-file-2 #0.png" ) ,
160
+ oldImgFixture
161
+ ) ;
162
+
163
+ cleanupImagesTask ( {
164
+ projectRoot,
165
+ env : { pluginVisualRegressionCleanupUnusedImages : true } ,
166
+ testingType : 'e2e' ,
167
+ } as unknown as Cypress . PluginConfigOptions ) ;
168
+
169
+ expect ( existsSync ( screenshotPath ) ) . toBe ( false ) ;
170
+ } ) ;
144
171
} ) ;
145
172
} ) ;
146
173
} ) ;
@@ -178,7 +205,7 @@ describe("compareImagesTask", () => {
178
205
describe ( "when old screenshot exists" , ( ) => {
179
206
it ( "resolves with a success message" , async ( ) =>
180
207
expect (
181
- compareImagesTask ( await generateConfig ( { updateImages : true } ) )
208
+ compareImagesTask ( { testingType : 'e2e' } , await generateConfig ( { updateImages : true } ) )
182
209
) . resolves . toEqual ( {
183
210
message :
184
211
"Image diff factor (0%) is within boundaries of maximum threshold option 0.5." ,
@@ -197,7 +224,7 @@ describe("compareImagesTask", () => {
197
224
const cfg = await generateConfig ( { updateImages : false } ) ;
198
225
await fs . unlink ( cfg . imgOld ) ;
199
226
200
- await expect ( compareImagesTask ( cfg ) ) . resolves . toEqual ( {
227
+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toEqual ( {
201
228
message :
202
229
"Image diff factor (0%) is within boundaries of maximum threshold option 0.5." ,
203
230
imgDiff : 0 ,
@@ -214,7 +241,7 @@ describe("compareImagesTask", () => {
214
241
it ( "resolves with an error message" , async ( ) => {
215
242
const cfg = await generateConfig ( { updateImages : false } ) ;
216
243
217
- await expect ( compareImagesTask ( cfg ) ) . resolves . toMatchSnapshot ( ) ;
244
+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toMatchSnapshot ( ) ;
218
245
} ) ;
219
246
} ) ;
220
247
@@ -223,7 +250,7 @@ describe("compareImagesTask", () => {
223
250
const cfg = await generateConfig ( { updateImages : false } ) ;
224
251
await writeTmpFixture ( cfg . imgNew , oldImgFixture ) ;
225
252
226
- await expect ( compareImagesTask ( cfg ) ) . resolves . toMatchSnapshot ( ) ;
253
+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toMatchSnapshot ( ) ;
227
254
} ) ;
228
255
} ) ;
229
256
} ) ;
0 commit comments