Skip to content

Commit

Permalink
Puppeteer: Cleanup (#25414)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeviPesin authored Feb 3, 2023
1 parent 138769e commit 43a4c84
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ jobs:
CI: [ 0, 1, 2, 3, 4, 5, 6, 7 ]
env:
CI: ${{ matrix.CI }}
FORCE_COLOR: 1
steps:
- name: Git checkout
uses: actions/checkout@v2
Expand Down
20 changes: 9 additions & 11 deletions test/e2e/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const chromiumChannel = 'stable'; // stable -> beta -> dev -> canary (Mac and Wi

const port = 1234;
const pixelThreshold = 0.1; // threshold error in one pixel
const maxFailedPixels = 0.05; // at most 5% failed pixels
const maxDifferentPixels = 0.05; // at most 5% different pixels

const networkTimeout = 90; // 90 seconds, set to 0 to disable
const renderTimeout = 4.5; // 4.5 seconds, set to 0 to disable
Expand Down Expand Up @@ -449,15 +449,13 @@ async function makeAttempt( page, failedScreenshots, cleanPage, isMakeScreenshot
const actual = screenshot.bitmap;
const diff = screenshot.clone();

let numFailedPixels;
let numDifferentPixels;

try {

numFailedPixels = pixelmatch( expected.bitmap.data, actual.data, diff.bitmap.data, actual.width, actual.height, {
numDifferentPixels = pixelmatch( expected.bitmap.data, actual.data, diff.bitmap.data, actual.width, actual.height, {
threshold: pixelThreshold,
alpha: 0.2,
diffMask: process.env.FORCE_COLOR === '0',
diffColor: process.env.FORCE_COLOR === '0' ? [ 255, 255, 255 ] : [ 255, 0, 0 ]
alpha: 0.2
} );

} catch {
Expand All @@ -466,19 +464,19 @@ async function makeAttempt( page, failedScreenshots, cleanPage, isMakeScreenshot

}

numFailedPixels /= actual.width * actual.height;
numDifferentPixels /= actual.width * actual.height;

/* Print results */

const percFailedPixels = 100 * numFailedPixels;
const differentPixels = 100 * numDifferentPixels;

if ( numFailedPixels < maxFailedPixels ) {
if ( numDifferentPixels < maxDifferentPixels ) {

console.green( `Diff ${ percFailedPixels.toFixed( 1 ) }% in file: ${ file }` );
console.green( `Diff ${ differentPixels.toFixed( 1 ) }% in file: ${ file }` );

} else {

throw new Error( `Diff wrong in ${ percFailedPixels.toFixed( 1 ) }% of pixels in file: ${ file }` );
throw new Error( `Diff wrong in ${ differentPixels.toFixed( 1 ) }% of pixels in file: ${ file }` );

}

Expand Down

0 comments on commit 43a4c84

Please sign in to comment.