Skip to content

fix(c8yscrn): Fix moving failure screenshots #201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,17 +309,19 @@ export function configureC8yScreenshotPlugin(
(config.screenshotsFolder as string) ??
(config.e2e.screenshotsFolder as string);

const isDiffEnabled = diffOptions != null;
const isTestFailure = details.testFailure === true;
const isDiffEnabled = diffOptions != null && !isTestFailure;
if (isDiffEnabled && !diffTarget) {
log(`Diffing enabled but no target folder found`);
finish(details);
}

const folders = [screenshotTarget];
if (isDiffEnabled && diffTarget)
if (isDiffEnabled && diffTarget) {
folders.push(
path.join(diffTarget, ...details.name.split("/").slice(0, -1))
);
}

folders.forEach((f) => {
if (!fs.existsSync(f)) {
Expand All @@ -331,20 +333,20 @@ export function configureC8yScreenshotPlugin(
});

if (!screenshotTarget) {
log(`No screenshot target folder found`);
log(`No screenshot target folder configured`);
finish(details);
}

// for Module API run(), overwrite option of the screenshot is not working
const screenshotFile =
overwrite === true ? newPath : appendCountIfPathExists(newPath);
const diffFile = path.join(diffTarget, `${details.name}.diff.png`);
log(`Diff file: ${diffFile}`);

if (!isDiffEnabled) {
moveFile(details.path, screenshotFile);
finish(newPath);
} else {
const diffFile = path.join(diffTarget, `${details.name}.diff.png`);
log(`Diff file: ${diffFile}`);
compare(details.path, screenshotFile, diffFile, diffOptions).then(
(diffResult) => {
log(`Diff result: ${JSON.stringify(diffResult)}`);
Expand Down Expand Up @@ -383,7 +385,9 @@ export function configureC8yScreenshotPlugin(

const disabled = config.env.C8Y_DISABLE_WEBSOCKET;
if (disabled === true || disabled === "true") {
log(`Websocket server disabled. Config file will not be watched and reloaded.`);
log(
`Websocket server disabled. Config file will not be watched and reloaded.`
);
return;
}

Expand Down
Loading