Browse Source

Puppeteer E2E test: Show actual and difference screenshots (#25410)

* Puppeteer: Show actual and diff screenshots

* Semicolons

* Fix warning
Levi Pesin 2 years ago
parent
commit
61a06c454b
3 changed files with 19 additions and 1 deletions
  1. 6 0
      .github/workflows/ci.yml
  2. 1 0
      .gitignore
  3. 12 1
      test/e2e/puppeteer.js

+ 6 - 0
.github/workflows/ci.yml

@@ -77,6 +77,12 @@ jobs:
 
 
       - name: === E2E testing ===
       - name: === E2E testing ===
         run: npm run test-e2e
         run: npm run test-e2e
+      - name: Upload output screenshots
+        uses: actions/upload-artifact@v3
+        with:
+          name: Output screenshots
+          path: test/e2e/output-screenshots
+          if-no-files-found: ignore
 
 
   e2e-cov:
   e2e-cov:
     name: "Examples ready for release"
     name: "Examples ready for release"

+ 1 - 0
.gitignore

@@ -13,5 +13,6 @@ test/treeshake/index.bundle.min.js
 test/treeshake/index-src.bundle.min.js
 test/treeshake/index-src.bundle.min.js
 test/treeshake/stats.html
 test/treeshake/stats.html
 test/e2e/chromium
 test/e2e/chromium
+test/e2e/output-screenshots
 
 
 **/node_modules
 **/node_modules

+ 12 - 1
test/e2e/puppeteer.js

@@ -142,6 +142,11 @@ process.on( 'SIGINT', () => close() );
 
 
 async function main() {
 async function main() {
 
 
+	/* Create output directories */
+
+	try { await fs.rm( 'test/e2e/output-screenshots', { recursive: true, force: true } ); } catch {}
+	try { await fs.mkdir( 'test/e2e/output-screenshots' ); } catch {}
+
 	/* Find files */
 	/* Find files */
 
 
 	const isMakeScreenshot = process.argv[ 2 ] === '--make';
 	const isMakeScreenshot = process.argv[ 2 ] === '--make';
@@ -522,10 +527,11 @@ async function makeAttempt( pages, failedScreenshots, cleanPage, isMakeScreensho
 
 
 			try {
 			try {
 
 
-				expected = await jimp.read( `examples/screenshots/${ file }.jpg` );
+				expected = ( await jimp.read( `examples/screenshots/${ file }.jpg` ) ).quality( jpgQuality );
 
 
 			} catch {
 			} catch {
 
 
+				await screenshot.writeAsync( `test/e2e/output-screenshots/${ file }-actual.jpg` );
 				throw new Error( `Screenshot does not exist: ${ file }` );
 				throw new Error( `Screenshot does not exist: ${ file }` );
 
 
 			}
 			}
@@ -544,6 +550,8 @@ async function makeAttempt( pages, failedScreenshots, cleanPage, isMakeScreensho
 
 
 			} catch {
 			} catch {
 
 
+				await screenshot.writeAsync( `test/e2e/output-screenshots/${ file }-actual.jpg` );
+				await expected.writeAsync( `test/e2e/output-screenshots/${ file }-expected.jpg` );
 				throw new Error( `Image sizes does not match in file: ${ file }` );
 				throw new Error( `Image sizes does not match in file: ${ file }` );
 
 
 			}
 			}
@@ -558,6 +566,9 @@ async function makeAttempt( pages, failedScreenshots, cleanPage, isMakeScreensho
 
 
 			} else {
 			} else {
 
 
+				await screenshot.writeAsync( `test/e2e/output-screenshots/${ file }-actual.jpg` );
+				await expected.writeAsync( `test/e2e/output-screenshots/${ file }-expected.jpg` );
+				await diff.writeAsync( `test/e2e/output-screenshots/${ file }-diff.jpg` );
 				throw new Error( `Diff wrong in ${ differentPixels.toFixed( 1 ) }% of pixels in file: ${ file }` );
 				throw new Error( `Diff wrong in ${ differentPixels.toFixed( 1 ) }% of pixels in file: ${ file }` );
 
 
 			}
 			}