Skip to content

Commit

Permalink
fix(testing): use viewport for Puppeteer screenshot clip dimensions
Browse files Browse the repository at this point in the history
Fixes #5353

STENCIL-1135
  • Loading branch information
tanner-reits committed Feb 13, 2024
1 parent 8de2ab5 commit e5aaa2e
Showing 1 changed file with 13 additions and 6 deletions.
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

0 comments on commit e5aaa2e

Please sign in to comment.