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

fix(testing): use viewport for Puppeteer screenshot clip dimensions #5359

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/testing/puppeteer/puppeteer-screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ export async function pageCompareScreenshot(
});
});

const screenshotOpts = createPuppeteerScreenshotOptions(opts);
const screenshotBuf = await page.screenshot(screenshotOpts);
const pixelmatchThreshold =
typeof opts.pixelmatchThreshold === 'number' ? opts.pixelmatchThreshold : screenshotBuildData.pixelmatchThreshold;

let width = emulateConfig.viewport.width;
let height = emulateConfig.viewport.height;

Expand All @@ -123,6 +118,11 @@ export async function pageCompareScreenshot(
}
}

const screenshotOpts = createPuppeteerScreenshotOptions(opts, width, height);
const screenshotBuf = await page.screenshot(screenshotOpts);
const pixelmatchThreshold =
typeof opts.pixelmatchThreshold === 'number' ? opts.pixelmatchThreshold : screenshotBuildData.pixelmatchThreshold;

const results = await compareScreenshot(
emulateConfig,
screenshotBuildData,
Expand All @@ -137,7 +137,7 @@ export async function pageCompareScreenshot(
return results;
}

function createPuppeteerScreenshotOptions(opts: ScreenshotOptions) {
function createPuppeteerScreenshotOptions(opts: ScreenshotOptions, width: number, height: number) {
const puppeteerOpts: puppeteer.ScreenshotOptions = {
type: 'png',
fullPage: opts.fullPage,
Expand All @@ -152,6 +152,13 @@ function createPuppeteerScreenshotOptions(opts: ScreenshotOptions) {
width: opts.clip.width,
height: opts.clip.height,
};
} else {
puppeteerOpts.clip = {
x: 0,
y: 0,
width,
height,
};
}

return puppeteerOpts;
Expand Down
Loading