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
khanhduy1407 committed Dec 14, 2024
1 parent 626f291 commit ff832ca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/declarations/rindo-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 @@ -157,13 +157,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 ff832ca

Please sign in to comment.