Skip to content

Commit

Permalink
generate screenshots during test
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jul 2, 2024
1 parent 3cedfc5 commit f3c17a7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🍔🍟🥤
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Use Node.js 😂
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: 18

- name: Test 🧪
run: |
npm ci
npm run check-ci
- name: Upload Artifact ⬆️
uses: actions/upload-artifact@v4
with:
path: ./screenshots/*.png
overwrite: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/docs
/dist
/screenshots
index.html

# -- clip-for-deploy-end --
Expand Down
11 changes: 9 additions & 2 deletions test/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function getExamples(port) {
.map(f => ({
url: `http://localhost:${port}/examples/${f}`,
js: exampleInjectJS,
screenshot: true,
}));
}

Expand Down Expand Up @@ -71,7 +72,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) {
Expand All @@ -87,9 +88,15 @@ 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)[1];
const path = `${dir}/${name}.png`;
await page.screenshot({path});
}
}


await browser.close();
server.close();

Expand Down

0 comments on commit f3c17a7

Please sign in to comment.