Skip to content

[TASK] fix relative paths for Mochawesome context screenshots #97

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
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
24 changes: 21 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ const getDirName = require('path').dirname;
const AWS = require('aws-sdk');
const path = require('path');
const sizeOf = require('image-size');
const Container = require('codeceptjs/lib/container');

/**
* Resemble.js helper class for CodeceptJS, this allows screen comparison
@@ -29,6 +30,23 @@ class ResembleHelper extends Helper {
return folderPath;
}

_resolveRelativePath(folderPath) {
let absolutePathOfImage = folderPath;
if (!path.isAbsolute(absolutePathOfImage)) {
absolutePathOfImage = path.resolve(global.codecept_dir, absolutePathOfImage) + "/";
}
let absolutePathOfReportFolder = global.output_dir;
// support mocha
if (Container.mocha() && typeof Container.mocha().options.reporterOptions.reportDir !== 'undefined') {
absolutePathOfReportFolder = Container.mocha().options.reporterOptions.reportDir;
}
// support mocha-multi-reporters
if (Container.mocha() && typeof Container.mocha().options.reporterOptions.mochawesomeReporterOptions.reportDir !== 'undefined') {
absolutePathOfReportFolder = Container.mocha().options.reporterOptions.mochawesomeReporterOptions.reportDir;
}
return path.relative(absolutePathOfReportFolder, absolutePathOfImage);
}

/**
* Compare Images
*
@@ -170,11 +188,11 @@ class ResembleHelper extends Helper {

if (mocha !== undefined && misMatch >= options.tolerance) {
await mocha.addMochawesomeContext("Base Image");
await mocha.addMochawesomeContext(this._getBaseImagePath(baseImage, options));
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getBaseImagePath(baseImage, options)));
await mocha.addMochawesomeContext("ScreenShot Image");
await mocha.addMochawesomeContext(this._getActualImagePath(baseImage));
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getActualImagePath(baseImage)));
await mocha.addMochawesomeContext("Diff Image");
await mocha.addMochawesomeContext(this._getDiffImagePath(baseImage));
await mocha.addMochawesomeContext(this.resolveImagePathRelativeFromReport(this._getDiffImagePath(baseImage)));
}
}