Skip to content
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

Add filename to result #78

Closed
wants to merge 11 commits into from

Conversation

cuff-links
Copy link

This PR adds the data for the filenames of the images that were created to the returned results. This is helpful when debugging test failures so you can output whatever exact image failed. If you have 5 different viewports, it can be helpful for displaying an image or pushing the image to some kind of cloud solution.

@cuff-links
Copy link
Author

@zinserjan Added the ability to return file data from the createReport call. Modified tests to account for this. All is green. Let me know what you think.

package.json Outdated
@@ -40,6 +40,7 @@
"lodash": "^4.13.1",
"node-resemble-js": "0.0.5",
"nodeclient-spectre": "^1.0.3",
"phantomjs-prebuilt": "^2.1.16",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this move to a dependency?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think this happened when I used yarn to add it. I will switch.

@cuff-links
Copy link
Author

Thanks for catching that, @emilyrohrbough.

Copy link
Owner

@zinserjan zinserjan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work. I like the idea, but I think this needs to be done in a different way to make this more generic. See my comments.

@@ -126,8 +126,9 @@ export default class BaseCompare {
return path.join(runtimeConfigPath, `${name}-${suffix}.json`);
}

createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions) {
createResultReport(filePaths, misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chaning the order of arguments is a breaking change for all guys who uses custom compare methods. I would like to avoid this. Moreover this is to inflexibel and only useful for file comparison. I suggest to replace filePaths with an object that wil be assigned via Object.assign to the returned object. Then custom or other compare methods can enhance the report with additional information.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zinserjan Would you rather I made it the last argument, then? That way, if I am remembering my JS correctly, the value would just be null for those who aren't using the functionality?

@@ -25,6 +25,13 @@ export default class LocalCompare extends BaseCompare {

const referenceExists = await fs.exists(referencePath);

var fileNames;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use const and assign value directly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


fileNames = {
reference: referencePath,
actual: screenshotPath
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • add diff property with value of null to make sure the property is always there
  • replace key actual with screenshot to be consistent with the referenceName , screenshotName and diffName option.

…om actual to screenshots for current taken screenshot. Added diff: null to response object.
@cuff-links
Copy link
Author

@zinserjan I looked at the travis build and the failure seems a little funky. Passed on node 6 failed on 8. And it didn't have anything to do with test logic failing. Unfortunately, I can't rerun the tests to see if this was just a fluke failure.

@cuff-links
Copy link
Author

@zinserjan @emilyrohrbough Can someone rerun this?

@cuff-links
Copy link
Author

Is this PR still missing something? I believe all points in the review were addressed. @zinserjan @emilyrohrbough

@emilyrohrbough
Copy link

@silne30 I don't have privs to rerun tests.

@cuff-links
Copy link
Author

cuff-links commented May 3, 2018 via email

@zinserjan
Copy link
Owner

@silne30 just restarted the test.
I'll review this PR later ;)

diff: null
};

return this.createResultReport(result.diff, result.pass, true, filenames);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove filesnames from spectre report. This method doesn't use any files.

@@ -126,12 +126,13 @@ export default class BaseCompare {
return path.join(runtimeConfigPath, `${name}-${suffix}.json`);
}

createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions) {
createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions, filePaths) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover this is to inflexibel and only useful for file comparison. I suggest to replace filePaths with an object that wil be assigned via Object.assign to the returned object. Then custom or other compare methods can enhance the report with additional information.

This method should be more generic like I already said. What I mean is the following:

  createResultReport(misMatchPercentage, isWithinMisMatchTolerance, isSameDimensions, options = {}) {
    return {
      ...options,
      misMatchPercentage,
      isWithinMisMatchTolerance,
      isSameDimensions,
      isExactSameImage: misMatchPercentage === 0,
    };
  }

This allows you to pass everything you want in and just merges this into the report object.

In your case you would call it the following for LocalCompare & SaveScreenshot. All other methods shouldn't be touched.

this.createResultReport(misMatchPercentage, true, isSameDimensions, {
  filenames: {
    reference: referencePath,
    screenshot: screenshotPath,
    diff: null,
  },
});

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Thanks for that. Had to look into the spread operator in ES6 because I thought ...options was a typo. XD

@cuff-links
Copy link
Author

cuff-links commented May 16, 2018

@zinserjan I think this is more what you were looking for. ^_^

@cuff-links
Copy link
Author

@zinserjan Is there anything else this needs?

@cuff-links
Copy link
Author

@emilyrohrbough @zinserjan I know you all are busy. Just making sure that there is nothing else that I can do on my end for this PR.

@@ -25,6 +25,15 @@ export default class LocalCompare extends BaseCompare {

const referenceExists = await fs.exists(referencePath);


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line

@@ -38,23 +47,25 @@ export default class LocalCompare extends BaseCompare {

const diffPath = this.getDiffFile(context);


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra line


return this.createResultReport(misMatchPercentage, false, isSameDimensions);
return this.createResultReport(misMatchPercentage, false, isSameDimensions, options);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: the var name options is misleading here as these are report results not config options.

@emilyrohrbough
Copy link

This looks good to me. Can you explain the reason for the phantom dependency change?

@cuff-links
Copy link
Author

cuff-links commented May 29, 2018

@emilyrohrbough
phantomjs was deprecated in favor of phantomjs-prebuilt.

return {
misMatchPercentage,
isWithinMisMatchTolerance,
isSameDimensions,
isExactSameImage: misMatchPercentage === 0
isExactSameImage: misMatchPercentage === 0,
...options

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: to be safe, wouldn't we want to spread options first? In the future, we could potentially override the other object properties if we add duplicate properties to the passed in fileNames object.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yuderekyu Sorry. I am a bit new to ES6 and all of it's goodness. Can you explain to me what you mean by "spread options first"? First where?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {
  ...options, //spread this first
  misMatchPercentage,
  isWithinMisMatchTolerance,
  isSameDimensions,
  isExactSameImage: misMatchPercentage === 0,
};

Just to be safe. If options somehow contains any other keys (misMatchPercentage, isWithinMismatchTolerance, isSameDimensions, isExactSameImage), then spreading options last would override those values.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha.

@cuff-links
Copy link
Author

@emilyrohrbough @yuderekyu @zinserjan We good now?

@cuff-links
Copy link
Author

Ummmm.....can this be merged now?

@cuff-links
Copy link
Author

??

@cuff-links
Copy link
Author

cuff-links commented Jul 5, 2018

@zinserjan I have many thumbs up here. Can this change be merged yet

@mgibas
Copy link

mgibas commented Jul 6, 2018

Thumbocracy 🤣
For real - maintainers either merge or reject - please please please :)

@cuff-links
Copy link
Author

@zinserjan @emilyrohrbough @yuderekyu Is there anything I may have missed?

@emilyrohrbough
Copy link

@silne30 I do not have the permissions to merge this PR. I use the wdio-visual-regression-service within a project which is why I have been active on this PR.

@cuff-links
Copy link
Author

@zinserjan Hitting the 90 day mark since last fix was made. Anything else this needs?

@cuff-links
Copy link
Author

Hope everything is okay. Please approve if this works. Please give me a feedback if I need to change something.

@cuff-links
Copy link
Author

@zinserjan Anyone?

@cuff-links
Copy link
Author

Not sure if this project has nodded off. We are looking at almost 9 months since feedback from last commit. I am not even using this tool anymore but I am hoping the PR get's pulled for anyone else who may want the functionality. @zinserjan Are you still looking into this?

@cuff-links
Copy link
Author

Gonna go ahead and close this. If we need it, we can reopen it. We are going on a year without any update since the last code change.

@cuff-links cuff-links closed this Jul 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants