Skip to content

Commit d79b45b

Browse files
committed
refactor: task.hook test suite
Signed-off-by: Jakub Freisler <[email protected]>
1 parent 82ccc0d commit d79b45b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/task.hook.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const generateConfig = async (cfg: Partial<CompareImagesCfg>) => ({
3131
...cfg,
3232
});
3333
const writeTmpFixture = async (pathToWriteTo: string, fixtureName: string) => {
34+
await fs.mkdir(path.dirname(pathToWriteTo), { recursive: true });
3435
await fs.writeFile(
3536
pathToWriteTo,
3637
await fs.readFile(path.join(fixturesPath, fixtureName))
@@ -56,29 +57,26 @@ describe("getScreenshotPathInfoTask", () => {
5657

5758
describe("cleanupImagesTask", () => {
5859
describe("when env is set", () => {
59-
const generateUsedScreenshot = async (projectRoot: string) => {
60+
const generateUsedScreenshotPath = async (projectRoot: string) => {
6061
const screenshotPathWithPrefix = generateScreenshotPath({
6162
titleFromOptions: "some-file",
6263
imagesDir: "images",
6364
specPath: "some/spec/path",
6465
});
65-
const screenshotPath = path.join(
66+
return path.join(
6667
projectRoot,
6768
screenshotPathWithPrefix.substring(
6869
IMAGE_SNAPSHOT_PREFIX.length + path.sep.length
6970
)
7071
);
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");
7772
};
7873

7974
it("does not remove used screenshot", async () => {
8075
const { path: projectRoot } = await dir();
81-
const screenshotPath = await generateUsedScreenshot(projectRoot);
76+
const screenshotPath = await writeTmpFixture(
77+
await generateUsedScreenshotPath(projectRoot),
78+
oldImgFixture
79+
);
8280

8381
cleanupImagesTask({
8482
projectRoot,
@@ -90,7 +88,10 @@ describe("cleanupImagesTask", () => {
9088

9189
it("removes unused screenshot", async () => {
9290
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+
);
9495

9596
cleanupImagesTask({
9697
projectRoot,

0 commit comments

Comments
 (0)