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

✨ Support multi-dom snapshots #1096

Merged
merged 6 commits into from
Oct 6, 2022
Merged

Conversation

wwilsman
Copy link
Contributor

@wwilsman wwilsman commented Oct 5, 2022

What is this?

This PR adds support for snapshots that may have differing DOM for different widths. In order to take advantage of this new feature, snapshot uploads must be deferred using the new defer-uploads config option. This is because all snapshot resources, including multiple root resources, must be discovered before the snapshot is sent to our infrastructure to be rendered for screenshots.

Changes

To facilitate multiple root resources, each root resource is identified by their associated widths using a new for-widths attribute for snapshot resources. When uploads are deferred, new snapshots of the same name will be merged with existing snapshots. While merging, previously discovered resources are discarded if they are no longer associated with any widths. This allows retries to work with multiple DOM snapshots when the same width snapshot is taken more than once.

For the percy snapshot command, the resource capture function was adjusted to take multi DOM snapshots between resizes by keeping track of the last width before the resize took place. When additional snapshots are defined, the page is resized back to it's initial size before each additional snapshot is iterated over.

For snapshots taken by SDKs using a domSnapshot option, they can now supply a singular width option instead of an array consisting of a single width. This should allow custom snapshot functions to more easily supply the width when iterating over snapshot sizes.

Examples

Required .percy.yml config:

version: 2
percy:
  defer-uploads: true

Puppeteer example:

await page.setViewport({ ...page.viewport(), width: 600 })
await percySnapshot(page, 'Response page', { width: 600 })
await page.setViewport({ ...page.viewport(), width: 1200 })
await percySnapshot(page, 'Response page', { width: 1200 })

Cypress example:

cy
  .viewport(600)
  .percySnapshot('Responsive page', { width: 600 })
  .viewport(1200)
  .percySnapshot('Responsive page', { width: 1200 })

@wwilsman wwilsman added the ✨ enhancement New feature or request label Oct 5, 2022
@wwilsman wwilsman requested a review from Robdel12 October 5, 2022 21:25
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

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

🏁 hell yeah. Pending passing tests of course

@wwilsman wwilsman force-pushed the ww/support-multi-dom-snapshots branch from 8ca1391 to 4a41126 Compare October 6, 2022 15:55
@wwilsman wwilsman merged commit 54fa2c1 into master Oct 6, 2022
@wwilsman wwilsman deleted the ww/support-multi-dom-snapshots branch October 6, 2022 16:16
@djones
Copy link

djones commented Oct 6, 2022

🎉🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants