@@ -31,6 +31,7 @@ const generateConfig = async (cfg: Partial<CompareImagesCfg>) => ({
31
31
...cfg ,
32
32
} ) ;
33
33
const writeTmpFixture = async ( pathToWriteTo : string , fixtureName : string ) => {
34
+ await fs . mkdir ( path . dirname ( pathToWriteTo ) , { recursive : true } ) ;
34
35
await fs . writeFile (
35
36
pathToWriteTo ,
36
37
await fs . readFile ( path . join ( fixturesPath , fixtureName ) )
@@ -56,29 +57,26 @@ describe("getScreenshotPathInfoTask", () => {
56
57
57
58
describe ( "cleanupImagesTask" , ( ) => {
58
59
describe ( "when env is set" , ( ) => {
59
- const generateUsedScreenshot = async ( projectRoot : string ) => {
60
+ const generateUsedScreenshotPath = async ( projectRoot : string ) => {
60
61
const screenshotPathWithPrefix = generateScreenshotPath ( {
61
62
titleFromOptions : "some-file" ,
62
63
imagesDir : "images" ,
63
64
specPath : "some/spec/path" ,
64
65
} ) ;
65
- const screenshotPath = path . join (
66
+ return path . join (
66
67
projectRoot ,
67
68
screenshotPathWithPrefix . substring (
68
69
IMAGE_SNAPSHOT_PREFIX . length + path . sep . length
69
70
)
70
71
) ;
71
- await fs . mkdir ( path . dirname ( screenshotPath ) , { recursive : true } ) ;
72
- return await writeTmpFixture ( screenshotPath , "screenshot.png" ) ;
73
- } ;
74
- const generateUnusedScreenshot = async ( projectRoot : string ) => {
75
- const screenshotPath = path . join ( projectRoot , "some-file-2 #0.png" ) ;
76
- return await writeTmpFixture ( screenshotPath , "screenshot.png" ) ;
77
72
} ;
78
73
79
74
it ( "does not remove used screenshot" , async ( ) => {
80
75
const { path : projectRoot } = await dir ( ) ;
81
- const screenshotPath = await generateUsedScreenshot ( projectRoot ) ;
76
+ const screenshotPath = await writeTmpFixture (
77
+ await generateUsedScreenshotPath ( projectRoot ) ,
78
+ oldImgFixture
79
+ ) ;
82
80
83
81
cleanupImagesTask ( {
84
82
projectRoot,
@@ -90,7 +88,10 @@ describe("cleanupImagesTask", () => {
90
88
91
89
it ( "removes unused screenshot" , async ( ) => {
92
90
const { path : projectRoot } = await dir ( ) ;
93
- const screenshotPath = await generateUnusedScreenshot ( projectRoot ) ;
91
+ const screenshotPath = await writeTmpFixture (
92
+ path . join ( projectRoot , "some-file-2 #0.png" ) ,
93
+ oldImgFixture
94
+ ) ;
94
95
95
96
cleanupImagesTask ( {
96
97
projectRoot,
0 commit comments