test(snapshots): use pdf as snapshot

This commit is contained in:
Nico Jansen 2023-01-30 11:57:53 +01:00 committed by Antonin Stefanutti
parent 2474dddfbb
commit 724cac997f
46 changed files with 17 additions and 7 deletions

View File

@ -14,7 +14,8 @@ jobs:
- uses: actions/checkout@v3
- run: npm ci
- run: npx playwright install firefox
- run: npm run test-prepare-pdfs
- run: npm run test:generate-snapshot-screenshots
- run: npm run test:generate-pdfs
- run: npm test
- uses: actions/upload-artifact@v3
if: always()

View File

@ -11,13 +11,13 @@ jobs:
token: ${{ secrets.GH_TOKEN }}
- run: npm ci
- run: npx playwright install firefox
- run: npm run test-prepare-pdfs
- run: npm test -- --update-snapshots
- run: npm run test:generate-pdfs
- run: rm -rf test/snapshot && mv test/output test/snapshot
- name: Commit
run: |
git config --global user.name 'Decktape bot'
git config --global user.email 'decktape-bot@users.noreply.github.com'
git pull
git add .
git commit -m "test(screenshots): update snapshots"
git commit -m "test(snapshots): update snapshot pdfs"
git push

4
.gitignore vendored
View File

@ -14,5 +14,9 @@
!README.adoc
!test/
test/output/
# Snapshot screenshots are regenerated based on the snapshot pdf
test/e2e.spec.ts-snapshots
!playwright.config.ts
!.github/

View File

@ -12,7 +12,8 @@
},
"scripts": {
"start": "node decktape.js",
"test-prepare-pdfs": "node test/run-decktape.js",
"test:generate-pdfs": "node test/run-decktape.js",
"test:generate-snapshot-screenshots": "SNAPSHOT=true playwright test --update-snapshots",
"test": "playwright test"
},
"repository": {

View File

@ -49,6 +49,7 @@ const config: PlaywrightTestConfig = {
webServer: {
command: `node test/run-server.js ${port}`,
port,
reuseExistingServer: true,
},
};

View File

@ -6,7 +6,10 @@ test.describe("e2e", () => {
inputDirectories.forEach((input) => {
test(`should have no visual regression for ${input}`, async ({ page }) => {
await page.goto(`/show-pdf.html?file=${input}`);
const dir = process.env.SNAPSHOT === 'true' ? 'snapshot' : 'output';
const url = `/show-pdf.html?file=${encodeURIComponent(`${dir}/${input}.pdf`)}`;
console.log(url);
await page.goto(url);
await page.waitForFunction(() => typeof deck === "object");
const theCanvas = page.locator("#the-canvas");
const numberOfPages = await page.evaluate(async () => deck.numPages);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 266 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

View File

@ -11,7 +11,7 @@
<script src="https://cdn.jsdelivr.net/npm/pdfjs-dist@3.1.81/build/pdf.min.js"></script>
<script type="module">
const params = new URLSearchParams(window.location.search);
const pdf = await pdfjsLib.getDocument(`./output/${params.get('file')}.pdf`).promise;
const pdf = await pdfjsLib.getDocument(params.get('file')).promise;
let currentPage = 1;
await renderPage();

Binary file not shown.