Skip to content

Commit b4eae41

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

File tree

1 file changed

+25
-24
lines changed
  • packages/cypress-plugin-visual-regression-diff/src

1 file changed

+25
-24
lines changed

packages/cypress-plugin-visual-regression-diff/src/commands.ts

+25-24
Original file line numberDiff line numberDiff line change
@@ -80,34 +80,35 @@ const getImagesDir = (options: Cypress.MatchImageOptions) => {
8080
return imagesDir;
8181
};
8282

83-
export const getConfig = (options: Cypress.MatchImageOptions) => {
83+
const getImagesPathConfig = (options: Cypress.MatchImageOptions) => {
8484
const imagesDir = getImagesDir(options);
8585

86-
return {
87-
scaleFactor:
88-
options.forceDeviceScaleFactor === false ||
89-
getPluginEnv("forceDeviceScaleFactor") === false
90-
? 1
91-
: 1 / window.devicePixelRatio,
92-
createMissingImages:
93-
options.createMissingImages ??
94-
getPluginEnv("createMissingImages") ??
95-
true,
96-
updateImages: options.updateImages ?? getPluginEnv("updateImages") ?? false,
97-
imagesPath:
98-
(imagesDir && `{spec_path}/${imagesDir}`) ||
99-
options.imagesPath ||
100-
getPluginEnv("imagesPath") ||
101-
"{spec_path}/__image_snapshots__",
102-
maxDiffThreshold:
103-
options.maxDiffThreshold ?? getPluginEnv("maxDiffThreshold") ?? 0.01,
104-
diffConfig: options.diffConfig || getPluginEnv("diffConfig") || {},
105-
screenshotConfig:
106-
options.screenshotConfig || getPluginEnv("screenshotConfig") || {},
107-
matchAgainstPath: options.matchAgainstPath || undefined,
108-
};
86+
return (
87+
(imagesDir && `{spec_path}/${imagesDir}`) ||
88+
options.imagesPath ||
89+
getPluginEnv("imagesPath") ||
90+
"{spec_path}/__image_snapshots__"
91+
);
10992
};
11093

94+
export const getConfig = (options: Cypress.MatchImageOptions) => ({
95+
scaleFactor:
96+
options.forceDeviceScaleFactor === false ||
97+
getPluginEnv("forceDeviceScaleFactor") === false
98+
? 1
99+
: 1 / window.devicePixelRatio,
100+
createMissingImages:
101+
options.createMissingImages ?? getPluginEnv("createMissingImages") ?? true,
102+
updateImages: options.updateImages ?? getPluginEnv("updateImages") ?? false,
103+
imagesPath: getImagesPathConfig(options),
104+
maxDiffThreshold:
105+
options.maxDiffThreshold ?? getPluginEnv("maxDiffThreshold") ?? 0.01,
106+
diffConfig: options.diffConfig || getPluginEnv("diffConfig") || {},
107+
screenshotConfig:
108+
options.screenshotConfig || getPluginEnv("screenshotConfig") || {},
109+
matchAgainstPath: options.matchAgainstPath || undefined,
110+
});
111+
111112
Cypress.Commands.add(
112113
"matchImage",
113114
{ prevSubject: "optional" },

0 commit comments

Comments
 (0)