Skip to content

Commit

Permalink
Allow snapshot strategy to be configured
Browse files Browse the repository at this point in the history
We want people to be able to use the new "clip" snapshot strategy that
happo-e2e has made available.

The clip strategy means the whole dom is included in the snapshot, and
happo workers will clip the screenshot based on where the
`[data-happo-clip]` element is located.
  • Loading branch information
trotzig authored and lencioni committed Jan 23, 2025
1 parent f4921e0 commit 5602c51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cypress/integration/home_page_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ describe('The Home Page', () => {
component: 'Card',
log: false,
});
cy.get('.card', { log: false }).happoScreenshot({
component: 'Card',
variant: 'snapshotStrategy clip',
log: false,
snapshotStrategy: 'clip',
});
cy.get('.card,.button', { log: false }).happoScreenshot({
includeAllElements: true,
component: 'Card + Button',
Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Cypress.Commands.add(
includeAllElements,
transformDOM,
targets,
snapshotStrategy = 'hoist',
...otherOptions
} = options;

Expand All @@ -75,6 +76,7 @@ Cypress.Commands.add(
element: includeAllElements ? originalSubject : originalSubject[0],
responsiveInlinedCanvases: resInCan,
transformDOM: transformDOM,
strategy: snapshotStrategy,
handleBase64Image: ({ src, base64Url }) => {
const rawBase64 = base64Url.replace(/^data:image\/png;base64,/, '');
const chunks = chunked(rawBase64, config.canvasChunkSize);
Expand Down

0 comments on commit 5602c51

Please sign in to comment.