From 04cf15559dfc659594c0d9323ef43ec7d35779e3 Mon Sep 17 00:00:00 2001 From: Gregg Tavares Date: Tue, 2 Jul 2024 10:35:12 -0700 Subject: [PATCH] add screenshots to build --- .github/workflows/test.yml | 6 ++++++ .gitignore | 1 + test/puppeteer.js | 10 +++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a511cd07..1391a077 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,3 +22,9 @@ jobs: run: | npm ci npm run check-ci + + - name: Upload Artifact ⬆️ + uses: actions/upload-artifact@v4 + with: + path: ./screenshots/*.png + overwrite: true diff --git a/.gitignore b/.gitignore index acb17a7e..8982d499 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .DS_Store .esm-cache .tscache +screenshots node_modules package-lock.json test/src/ts/dist/* diff --git a/test/puppeteer.js b/test/puppeteer.js index 4fea574a..e58ee513 100755 --- a/test/puppeteer.js +++ b/test/puppeteer.js @@ -17,6 +17,7 @@ function getExamples(port) { .map(f => ({ url: `http://localhost:${port}/examples/${f}`, js: exampleInjectJS, + screenshot: true, })); } @@ -65,7 +66,7 @@ async function test(port) { ...getExamples(port), ]; - for (const {url, js} of testPages) { + for (const {url, js, screenshot} of testPages) { waitingPromiseInfo = makePromiseInfo(); console.log(`===== [ ${url} ] =====`); if (js) { @@ -81,6 +82,13 @@ async function test(port) { }); } await waitingPromiseInfo.promise; + if (screenshot) { + const dir = 'screenshots'; + fs.mkdirSync(dir, { recursive: true }); + const name = /\/([a-z0-9_-]+).html/.exec(url); + const path = `${dir}/${name}.png`; + await page.screenshot({path}); + } } await browser.close();