@@ -48,6 +48,7 @@ describe("getScreenshotPathInfoTask", () => {
4848 titleFromOptions : "some-title-withśpęćiał人物" ,
4949 imagesPath : "nested/images/dir" ,
5050 specPath,
51+ currentRetryNumber : 0 ,
5152 } )
5253 ) . toEqual ( {
5354 screenshotPath :
@@ -62,6 +63,7 @@ describe("getScreenshotPathInfoTask", () => {
6263 titleFromOptions : "some-title" ,
6364 imagesPath : "{spec_path}/images/dir" ,
6465 specPath,
66+ currentRetryNumber : 0 ,
6567 } )
6668 ) . toEqual ( {
6769 screenshotPath :
@@ -76,6 +78,7 @@ describe("getScreenshotPathInfoTask", () => {
7678 titleFromOptions : "some-title" ,
7779 imagesPath : "/images/dir" ,
7880 specPath,
81+ currentRetryNumber : 0 ,
7982 } )
8083 ) . toEqual ( {
8184 screenshotPath :
@@ -88,6 +91,7 @@ describe("getScreenshotPathInfoTask", () => {
8891 titleFromOptions : "some-title" ,
8992 imagesPath : "C:/images/dir" ,
9093 specPath,
94+ currentRetryNumber : 0 ,
9195 } )
9296 ) . toEqual ( {
9397 screenshotPath :
@@ -104,6 +108,7 @@ describe("cleanupImagesTask", () => {
104108 titleFromOptions : "some-file" ,
105109 imagesPath : "images" ,
106110 specPath : "some/spec/path" ,
111+ currentRetryNumber : 0 ,
107112 } ) ;
108113 return path . join (
109114 projectRoot ,
@@ -113,34 +118,56 @@ describe("cleanupImagesTask", () => {
113118 ) ;
114119 } ;
115120
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+ ) ;
122128
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 ) ;
127134
128- expect ( existsSync ( screenshotPath ) ) . toBe ( true ) ;
135+ expect ( existsSync ( screenshotPath ) ) . toBe ( true ) ;
136+ } ) ;
129137 } ) ;
130138
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+ ) ;
137146
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 ) ;
142152
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+ } ) ;
144171 } ) ;
145172 } ) ;
146173} ) ;
@@ -178,7 +205,7 @@ describe("compareImagesTask", () => {
178205 describe ( "when old screenshot exists" , ( ) => {
179206 it ( "resolves with a success message" , async ( ) =>
180207 expect (
181- compareImagesTask ( await generateConfig ( { updateImages : true } ) )
208+ compareImagesTask ( { testingType : 'e2e' } , await generateConfig ( { updateImages : true } ) )
182209 ) . resolves . toEqual ( {
183210 message :
184211 "Image diff factor (0%) is within boundaries of maximum threshold option 0.5." ,
@@ -197,7 +224,7 @@ describe("compareImagesTask", () => {
197224 const cfg = await generateConfig ( { updateImages : false } ) ;
198225 await fs . unlink ( cfg . imgOld ) ;
199226
200- await expect ( compareImagesTask ( cfg ) ) . resolves . toEqual ( {
227+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toEqual ( {
201228 message :
202229 "Image diff factor (0%) is within boundaries of maximum threshold option 0.5." ,
203230 imgDiff : 0 ,
@@ -214,7 +241,7 @@ describe("compareImagesTask", () => {
214241 it ( "resolves with an error message" , async ( ) => {
215242 const cfg = await generateConfig ( { updateImages : false } ) ;
216243
217- await expect ( compareImagesTask ( cfg ) ) . resolves . toMatchSnapshot ( ) ;
244+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toMatchSnapshot ( ) ;
218245 } ) ;
219246 } ) ;
220247
@@ -223,7 +250,7 @@ describe("compareImagesTask", () => {
223250 const cfg = await generateConfig ( { updateImages : false } ) ;
224251 await writeTmpFixture ( cfg . imgNew , oldImgFixture ) ;
225252
226- await expect ( compareImagesTask ( cfg ) ) . resolves . toMatchSnapshot ( ) ;
253+ await expect ( compareImagesTask ( { testingType : 'e2e' } , cfg ) ) . resolves . toMatchSnapshot ( ) ;
227254 } ) ;
228255 } ) ;
229256 } ) ;
0 commit comments