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

test(core): add visual regression testing #962

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

etowahadams
Copy link
Contributor

@etowahadams etowahadams commented Aug 17, 2023

Fix #958
Toward #

Adds a yarn screenshot command. This command will use dist/gosling.js in a headless browser (using puppeteer) and take a screenshot of the visualization that is included in the editor. It will save these screenshots in img/visual-regression/new-screenshots. If there is a difference compared to the screenshots in img/visual-regression/screenshotsit will show the differences in an image in img/visual-regression/diffs.

Interestingly, the Gosling genomic axis is non-deterministic for many specs. Parts of the axis will look different between renders. This makes automated visual regression testing unsuitable. I think this best used as a check when testing locally to make sure that many visualizations are not impacted.

Checklist

  • Ensure the PR works with all demos on the online editor
  • Unit tests added or updated
  • Examples added or updated
  • Documentation updated (e.g., added API functions)
  • Screenshots for visual changes (e.g., new encoding support or UI change on Editor)

@etowahadams etowahadams changed the title Pupeteer visual regression of spec examples Puppeteer visual regression of spec examples Aug 17, 2023
@etowahadams etowahadams changed the title Puppeteer visual regression of spec examples test: add visual regression testing Sep 25, 2023
@etowahadams etowahadams changed the title test: add visual regression testing test(core): add visual regression testing Sep 25, 2023
Comment on lines +134 to +146
const screenshot = defineConfig({
test: {
include: ['./img/visual-regression/*'],
globals: true,
environment: 'jsdom',
threads: false,
environmentOptions: {
jsdom: {
resources: 'usable'
}
}
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New config to be used only when yarn screenshot is called so that only tests in img/visual-regression will be run

@etowahadams etowahadams requested a review from sehilyi September 25, 2023 20:43
@etowahadams
Copy link
Contributor Author

Ready for review. I finally felt inspired to try new things after I was unable to get workers to work in puppeteer. Turns out workers don't work if there is no URL. The trick is to navigate to a page first, then to change the content of the page. I spent way too long figuring this out 😭

I decided not to make this visual regression test automated for now because many gosling visualizations are non deterministic. In particular, the axis seems to have some non-deterministic behavior when zoomed out. Here is an example of the diff between two renderings of the doc_point spec. In red are the regions which do not match between old and new renders. About 20 of the specs had this behavior. This might be a bug that we should fix.

Still, I think this should be a useful tool to understand the extend of visual changes.

image

@etowahadams etowahadams marked this pull request as ready for review September 26, 2023 15:49
@sehilyi sehilyi self-assigned this Sep 27, 2023
Comment on lines +24 to +36
<link rel="stylesheet" href="${baseUrl}/higlass@${higlassVersion}/dist/hglib.css">
<script src="${baseUrl}/react@${reactVersion}/umd/react.production.min.js"></script>
<script src="${baseUrl}/react-dom@${reactVersion}/umd/react-dom.production.min.js"></script>
<script src="${baseUrl}/pixi.js@${pixijsVersion}/dist/browser/pixi.min.js"></script>
<script src="${baseUrl}/higlass@${higlassVersion}/dist/hglib.js"></script>
<script type="text/javascript">${gosling}</script>
<body>
<div id="vis"></div>
<script>
gosling.embed(document.getElementById("vis"), JSON.parse(\`${spec}\`))
</script>
</body>
</html>`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will have to change when we update Gosling to only have a ESM build

@etowahadams
Copy link
Contributor Author

Any updates on this? I think this will be quite useful when implementing performance related improvements.

@sehilyi
Copy link
Member

sehilyi commented Oct 17, 2023

Thank you for the reminder! And, sorry, I lost track of this.

Regarding the change of the axis, what do you think of making the visibility of ticks deterministic? We can remove the use of random values for determining the visibility, and it might be as simple as removing the following line:

.sort((a, b) => b.importance - a.importance)

CONTRIBUTING.md Outdated Show resolved Hide resolved
## Visual Regression

To test if your changes make a difference visually across a large number of specifications, you can use can use the `yarn screenshot` command.
This command will use `dist/gosling.js` in a headless browser (using puppeteer) and take a screenshot of the visualization that is included in the editor.
Copy link
Member

@sehilyi sehilyi Oct 17, 2023

Choose a reason for hiding this comment

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

You could briefly mention that one needs to run yarn build before yarn screenshot to test the updated Gosling.js.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add!

CONTRIBUTING.md Outdated

To test if your changes make a difference visually across a large number of specifications, you can use can use the `yarn screenshot` command.
This command will use `dist/gosling.js` in a headless browser (using puppeteer) and take a screenshot of the visualization that is included in the editor.
It will save these screenshots in `img/visual-regression/new-screenshots`. If there is a difference compared to the screenshots in `img/visual-regression/screenshots`
Copy link
Member

Choose a reason for hiding this comment

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

So, for now, would the usage pattern be like (occasionally) running the yarn build and yarn screenshot and then moving all files under img/visual-regression/new-screenshots to img/visual-regression/screenshots?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how I currently see it being used in its current state, yes. I can add this as usage pattern in the documentation. I can also add a command which moves the screenshots from img/visual-regression/new-screenshots to img/visual-regression/screenshots.

Copy link
Member

@sehilyi sehilyi left a comment

Choose a reason for hiding this comment

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

This looks like a very useful feature! Thank you for making these chnages.

One thing I notice is when I run yarn, yarn build, and yarn screenshot, I am getting the following error complaining that the new-screenshots/* are not found. Just in case it is related to wait times, I tested with larger values for related parameters, e.g., idelTime, delay(), but it shows the same issue. There must be something that I am missing. Do you have any clue about this issue?

Screenshot 2023-10-17 at 15 00 47

@sehilyi
Copy link
Member

sehilyi commented Oct 17, 2023

Update: It looks like I needed to create empty new-screenshots and diffs folders first. I thinks this can be added to the yarn screenshot script.

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.

Automated testing for rendered visualization differences
2 participants