Skip to content

Commit

Permalink
test(integration): blur screenshots before comparison
Browse files Browse the repository at this point in the history
I've spent quite a while trying various options to reduce the number of failures due to
antialiasing differences, without success. This takes a bit more of an extreme option to blur the
screenshot slightly to try and normalise it. The goal of the test isn't pixel-precision, so this
should be ok.

Ideally, this will be a feature in Playwright (so the reference image doesn't have to be blurred
too).

Refs #388, microsoft/playwright#7548
  • Loading branch information
thewilkybarkid committed Aug 3, 2021
1 parent 39fa33b commit d36ae9d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 10 deletions.
2 changes: 1 addition & 1 deletion integration/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY \
./

RUN \
npm ci \
npm ci --production \
&& npm cache clean --force

ENTRYPOINT ["wait-for-it", "prereview:3000", "--strict", "--"]
Expand Down
33 changes: 30 additions & 3 deletions integration/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion integration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"private": true,
"dependencies": {
"@playwright/test": "^1.13.0"
"@playwright/test": "^1.13.0",
"glur": "^1.1.2",
"pngjs": "^6.0.0"
},
"devDependencies": {
"@types/glur": "^1.1.1",
"@types/pngjs": "^6.0.1"
}
}
3 changes: 2 additions & 1 deletion integration/src/home.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { test, expect } from '@playwright/test';
import { blur } from './utils';

test.describe('homepage', () => {
test('looks correct', async ({ page }) => {
Expand All @@ -11,7 +12,7 @@ test.describe('homepage', () => {
const carouselControls = await page.$$('.slick-dots :text("1")');
await Promise.all(carouselControls.map(controls => controls.click()));

const screenshot = await page.screenshot({ fullPage: true });
const screenshot = await page.screenshot({ fullPage: true }).then(blur);

expect(screenshot).toMatchSnapshot('home.png');
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions integration/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import glur from 'glur';
import { PNG } from 'pngjs';

export function blur(image: Buffer): Buffer {
const png = PNG.sync.read(image);

glur(png.data, png.width, png.height, 5);

return PNG.sync.write(png, { filterType: 4 });
}

0 comments on commit d36ae9d

Please sign in to comment.