Skip to content

Commit

Permalink
feat(testing): expose captureBeyondViewport in pageCompareScreenshot (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann authored Jun 13, 2024
1 parent b6d2404 commit cf6a450
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/declarations/stencil-private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,12 @@ export interface ScreenshotOptions {
* more sensitive. Defaults to the testing config `pixelmatchThreshold` value;
*/
pixelmatchThreshold?: number;
/**
* Capture the screenshot beyond the viewport.
*
* @defaultValue `false` if there is no `clip`. `true` otherwise.
*/
captureBeyondViewport?: boolean;
}

export interface ScreenshotBoundingBox {
Expand Down
4 changes: 4 additions & 0 deletions src/testing/puppeteer/puppeteer-screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,17 @@ export function createPuppeteerScreenshotOptions(
};

if (opts.clip) {
puppeteerOpts.captureBeyondViewport =
typeof opts.captureBeyondViewport === 'boolean' ? opts.captureBeyondViewport : true;
puppeteerOpts.clip = {
x: opts.clip.x,
y: opts.clip.y,
width: opts.clip.width,
height: opts.clip.height,
};
} else {
puppeteerOpts.captureBeyondViewport =
typeof opts.captureBeyondViewport === 'boolean' ? opts.captureBeyondViewport : false;
puppeteerOpts.clip = {
x: 0,
y: 0,
Expand Down
2 changes: 2 additions & 0 deletions src/testing/puppeteer/test/puppeteer-screenshot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Puppeteer Screenshot', () => {
width: 800,
height: 600,
});
expect(options.captureBeyondViewport).toBe(false);
});

it('should use clip options if provided', () => {
Expand All @@ -32,6 +33,7 @@ describe('Puppeteer Screenshot', () => {
width: 100,
height: 200,
});
expect(options.captureBeyondViewport).toBe(true);
});
});
});

0 comments on commit cf6a450

Please sign in to comment.