Skip to content

Commit 59aabc4

Browse files
committed
testing ghwf for changes
1 parent 7be3fb6 commit 59aabc4

File tree

4 files changed

+168
-4
lines changed

4 files changed

+168
-4
lines changed

.github/workflows/visualdiffs.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Visual URL Comparison
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
visual-diff:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Install deps for PR build
14+
run: npm ci
15+
16+
- name: Install Playwright browsers
17+
run: npx playwright install --with-deps
18+
19+
- name: Build PR version
20+
run: npm run build
21+
22+
- name: Serve PR build
23+
run: npm run preview -- --port 3001 &
24+
25+
# Checkout base branch and build
26+
- name: Checkout base branch
27+
run: |
28+
git fetch origin ${{ github.event.pull_request.base.ref }} --depth=1
29+
git checkout FETCH_HEAD
30+
31+
- name: Install deps for base build
32+
run: npm ci
33+
34+
- name: Build base version
35+
run: npm run build
36+
37+
- name: preview vite build
38+
run: npm run preview -- --port 3002 &
39+
40+
# Run screenshot diff script
41+
- name: Run visual diff
42+
run: node scripts/visualDiff.js
43+
44+
- uses: actions/upload-artifact@v3
45+
with:
46+
name: visual-diffs
47+
path: diffs

package-lock.json

Lines changed: 77 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"eslint": "^9.33.0",
2929
"eslint-plugin-react": "^7.32.2",
3030
"eslint-plugin-react-hooks": "^5.2.0",
31+
"pixelmatch": "^7.1.0",
32+
"playwright": "^1.57.0",
33+
"pngjs": "^7.0.0",
3134
"tailwindcss": "^4.1.16",
3235
"vite": "^7.1.2"
3336
}

scripts/visualDiff.cjs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
const { chromium } = require("playwright");
2+
const pixelmatch = require("pixelmatch").default || require("pixelmatch");
3+
const { PNG } = require("pngjs");
4+
const fs = require("fs");
5+
6+
const urls = [{ name: "home", path: "/" }];
7+
8+
async function run() {
9+
if (!fs.existsSync("diffs")) fs.mkdirSync("diffs");
10+
11+
const browser = await chromium.launch();
12+
13+
for (const { name, path } of urls) {
14+
const page = await browser.newPage();
15+
16+
// PR screenshot
17+
await page.goto(`http://localhost:5173${path}`);
18+
await page.screenshot({ path: `diffs/${name}_pr.png`, fullPage: true });
19+
20+
// Base screenshot
21+
await page.goto(`http://localhost:5173${path}`);
22+
await page.screenshot({ path: `diffs/${name}_base.png`, fullPage: true });
23+
24+
// Compare
25+
const img1 = PNG.sync.read(fs.readFileSync(`diffs/${name}_base.png`));
26+
const img2 = PNG.sync.read(fs.readFileSync(`diffs/${name}_pr.png`));
27+
const out = new PNG({ width: img1.width, height: img1.height });
28+
29+
pixelmatch(img1.data, img2.data, out.data, img1.width, img1.height, {
30+
threshold: 0.3,
31+
});
32+
33+
fs.writeFileSync(`diffs/${name}_diff.png`, PNG.sync.write(out));
34+
35+
await page.close();
36+
}
37+
38+
await browser.close();
39+
}
40+
41+
run();

0 commit comments

Comments
 (0)