From 8c228f965a16140d0fb00864aba4d4f91a353278 Mon Sep 17 00:00:00 2001 From: David Nguyen Date: Fri, 31 Oct 2025 15:06:20 +1100 Subject: [PATCH] fix: test --- .../e2e/envelopes/envelope-alignment.spec.ts | 27 ++++++++++++------ .../visual-regression/blank-certificate.png | Bin 0 -> 340 bytes 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 packages/app-tests/visual-regression/blank-certificate.png diff --git a/packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts b/packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts index 75ad5dd17..a313201df 100644 --- a/packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts +++ b/packages/app-tests/e2e/envelopes/envelope-alignment.spec.ts @@ -23,6 +23,7 @@ import type { TestInfo } from '@playwright/test'; import { expect, test } from '@playwright/test'; import { DocumentStatus } from '@prisma/client'; import fs from 'node:fs'; +import path from 'node:path'; import * as pdfjsLib from 'pdfjs-dist/legacy/build/pdf.js'; import { getFile } from '@documenso/lib/universal/upload/get-file'; @@ -90,7 +91,7 @@ test('field placement visual regression', async ({ page }, testInfo) => { }, }); - const storedImages = fs.readdirSync(`packages/app-tests/visual-regression`); + const storedImages = fs.readdirSync(path.join(__dirname, '../../visual-regression')); await Promise.all( completedDocument.envelopeItems.map(async (item) => { @@ -98,7 +99,7 @@ test('field placement visual regression', async ({ page }, testInfo) => { const loadedImages = storedImages .filter((image) => image.includes(item.title)) - .map((image) => fs.readFileSync(`packages/app-tests/visual-regression/${image}`)); + .map((image) => fs.readFileSync(path.join(__dirname, '../../visual-regression', image))); await compareSignedPdfWithImages({ id: item.title.replaceAll(' ', '-').toLowerCase(), @@ -179,7 +180,7 @@ test.skip('download envelope images', async ({ page }) => { for (const [index, { image }] of pdfImages.entries()) { fs.writeFileSync( - `packages/app-tests/visual-regression/${item.title}-${index}.png`, + path.join(__dirname, '../../visual-regression', `${item.title}-${index}.png`), new Uint8Array(image), ); } @@ -231,18 +232,25 @@ const compareSignedPdfWithImages = async ({ }: CompareSignedPdfWithImagesOptions) => { const renderedImages = await renderPdfToImage(pdfData); + const blankCertificateFile = fs.readFileSync( + path.join(__dirname, '../../visual-regression/blank-certificate.png'), + ); + const blankCertificateImage = PNG.sync.read(blankCertificateFile).data; + for (const [index, { image, width, height }] of renderedImages.entries()) { const isCertificate = index === renderedImages.length - 1; const diff = new PNG({ width, height }); - const storedImage = new Uint8Array(PNG.sync.read(images[index]).data); + const storedImage = PNG.sync.read(images[index]).data; - const newImage = new Uint8Array(PNG.sync.read(image).data); + const newImage = PNG.sync.read(image).data; + + const oldImage = isCertificate ? blankCertificateImage : storedImage; const comparison = pixelMatch( - storedImage, - newImage, + new Uint8Array(oldImage), + new Uint8Array(newImage), // eslint-disable-next-line @typescript-eslint/consistent-type-assertions diff.data as unknown as Uint8Array, width, @@ -254,12 +262,13 @@ const compareSignedPdfWithImages = async ({ ); console.log(`${id}-${index}: ${comparison}`); - const filePath = testInfo.outputPath(`diff-${id}-${index}.png`); + const filePath = path.join(testInfo.outputPath(), `diff-${id}-${index}.png`); fs.writeFileSync(filePath, new Uint8Array(PNG.sync.write(diff))); if (isCertificate) { - expect(comparison).toBeLessThan(20000); + // Expect the certificate to NOT be blank. Since the storedImage is blank. + expect(comparison).toBeGreaterThan(20000); } else { expect(comparison).toEqual(0); } diff --git a/packages/app-tests/visual-regression/blank-certificate.png b/packages/app-tests/visual-regression/blank-certificate.png new file mode 100644 index 0000000000000000000000000000000000000000..f3132e9a12c5adfa056f019b3df9383049a8c009 GIT binary patch literal 340 zcmeAS@N?(olHy`uVBq!ia0y~yU|G(LasB`Q|MDZ!Cm0wQ zc|2VlLn`LHJ;=xllsvTHyMHd9`2rww#DNBW=G)Z_jCplwk3oL-boFyt=akR{0DPkx A+5i9m literal 0 HcmV?d00001