Skip to content

Commit e78ab4b

Browse files
committed
chore: reduce complexity of generateScreenshotPath
Signed-off-by: Jakub Freisler <[email protected]>
1 parent 2eaee9e commit e78ab4b

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

packages/cypress-plugin-visual-regression-diff/src/screenshotPath.utils.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ const resetMap = (map: Record<string, unknown>) => {
1515
for (const key in map) delete map[key];
1616
};
1717

18+
const parsePathPartVariables = (
19+
specPath: string,
20+
pathPart: string,
21+
i: number
22+
) => {
23+
if (pathPart === PATH_VARIABLES.specPath) {
24+
return path.dirname(specPath);
25+
} else if (i === 0 && !pathPart) {
26+
// when unix-like absolute path
27+
return PATH_VARIABLES.unixSystemRootPath;
28+
} else if (i === 0 && WINDOWS_LIKE_DRIVE_REGEX.test(pathPart)) {
29+
// when win-like absolute path
30+
return path.join(PATH_VARIABLES.winSystemRootPath, pathPart[0]);
31+
}
32+
33+
return pathPart;
34+
};
35+
1836
export const generateScreenshotPath = ({
1937
titleFromOptions,
2038
imagesPath,
@@ -26,22 +44,8 @@ export const generateScreenshotPath = ({
2644
specPath: string;
2745
currentRetryNumber: number;
2846
}) => {
29-
const parsePathPartVariables = (pathPart: string, i: number) => {
30-
if (pathPart === PATH_VARIABLES.specPath) {
31-
return path.dirname(specPath);
32-
} else if (i === 0 && !pathPart) {
33-
// when unix-like absolute path
34-
return PATH_VARIABLES.unixSystemRootPath;
35-
} else if (i === 0 && WINDOWS_LIKE_DRIVE_REGEX.test(pathPart)) {
36-
// when win-like absolute path
37-
return path.join(PATH_VARIABLES.winSystemRootPath, pathPart[0]);
38-
}
39-
40-
return pathPart;
41-
};
42-
4347
const screenshotPath = path.join(
44-
...imagesPath.split("/").map(parsePathPartVariables),
48+
...imagesPath.split("/").map(parsePathPartVariables.bind(void 0, specPath)),
4549
sanitize(titleFromOptions)
4650
);
4751

0 commit comments

Comments
 (0)