Skip to content

Commit 0c48a0c

Browse files
committed
fix: Playwright package release build
1 parent 0ee014f commit 0c48a0c

13 files changed

Lines changed: 154 additions & 37 deletions

File tree

.github/workflows/build.yml

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- name: Checkout code
15-
uses: actions/checkout@v4
15+
uses: actions/checkout@v5
1616

1717
- name: Setup Zig
1818
uses: mlugg/setup-zig@v2
@@ -127,7 +127,7 @@ jobs:
127127
shell: bash
128128
steps:
129129
- name: Checkout code
130-
uses: actions/checkout@v4
130+
uses: actions/checkout@v5
131131

132132
- name: Setup Zig
133133
uses: mlugg/setup-zig@v2
@@ -175,7 +175,7 @@ jobs:
175175
shell: bash
176176
steps:
177177
- name: Checkout code
178-
uses: actions/checkout@v4
178+
uses: actions/checkout@v5
179179

180180
- name: Setup Zig
181181
uses: mlugg/setup-zig@v2
@@ -203,7 +203,7 @@ jobs:
203203
runs-on: ubuntu-latest
204204
steps:
205205
- name: Checkout code
206-
uses: actions/checkout@v4
206+
uses: actions/checkout@v5
207207

208208
- name: Download x86_64-linux artifact
209209
uses: actions/download-artifact@v4
@@ -238,7 +238,7 @@ jobs:
238238
image: mcr.microsoft.com/playwright:v1.56.0-noble
239239
steps:
240240
- name: Checkout code
241-
uses: actions/checkout@v4
241+
uses: actions/checkout@v5
242242

243243
- name: Download x86_64-linux artifact
244244
uses: actions/download-artifact@v4
@@ -274,12 +274,63 @@ jobs:
274274
path: npm_packages/playwright-odiff/test-results
275275
retention-days: 7
276276

277+
valgrind:
278+
name: Valgrind Memory Check
279+
runs-on: ubuntu-latest
280+
steps:
281+
- name: Checkout code
282+
uses: actions/checkout@v5
283+
284+
- name: Setup Zig
285+
uses: mlugg/setup-zig@v2
286+
with:
287+
version: 0.15.2
288+
289+
- name: Install nasm and valgrind
290+
run: |
291+
sudo apt-get update
292+
sudo apt-get install -y nasm valgrind
293+
294+
- name: Build with debug symbols
295+
run: |
296+
zig build -Doptimize=Debug
297+
298+
- name: Run valgrind memcheck - normal mode with diff output
299+
run: |
300+
set +e
301+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=99 --errors-for-leak-kinds=definite,possible \
302+
--suppressions=.valgrind.supp \
303+
./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png /tmp/diff-output.png 2>&1 | grep -vE "(DWARF2 reader: Badly formed|Can't handle line info entry)"
304+
EXIT_CODE=$?
305+
if [ $EXIT_CODE -eq 99 ]; then
306+
echo "ERROR: Valgrind detected memory errors!"
307+
exit 1
308+
else
309+
echo "Valgrind passed, command exit code: $EXIT_CODE"
310+
exit 0
311+
fi
312+
313+
- name: Run valgrind memcheck - normal mode without diff output
314+
run: |
315+
set +e
316+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=99 --errors-for-leak-kinds=definite,possible \
317+
--suppressions=.valgrind.supp \
318+
./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png 2>&1 | grep -vE "(DWARF2 reader: Badly formed|Can't handle line info entry)"
319+
EXIT_CODE=$?
320+
if [ $EXIT_CODE -eq 99 ]; then
321+
echo "ERROR: Valgrind detected memory errors!"
322+
exit 1
323+
else
324+
echo "Valgrind passed, command exit code: $EXIT_CODE"
325+
exit 0
326+
fi
327+
277328
spellcheck:
278329
name: Spell check
279330
runs-on: ubuntu-latest
280331
steps:
281332
- name: Checkout code
282-
uses: actions/checkout@v4
333+
uses: actions/checkout@v5
283334

284335
- name: Run typos
285336
uses: crate-ci/typos@master
@@ -293,7 +344,7 @@ jobs:
293344
runs-on: ubuntu-latest
294345
steps:
295346
- name: Checkout
296-
uses: actions/checkout@v1
347+
uses: actions/checkout@v5
297348

298349
- name: Download all built binaries
299350
uses: actions/download-artifact@v4
@@ -321,7 +372,7 @@ jobs:
321372
registry-url: "https://registry.npmjs.org"
322373
cache-dependency-path: "package-lock.json"
323374

324-
- name: Copy root readme
375+
- name: Copy root readme
325376
run: cp README.md npm_packages/odiff-bin/README.md
326377

327378
- name: Publish odiff-bin package
@@ -330,6 +381,10 @@ jobs:
330381
env:
331382
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
332383

384+
- name: Build playwright-odiff package
385+
working-directory: npm_packages/playwright-odiff
386+
run: npm run build
387+
333388
- name: Publish playwright-odiff package
334389
working-directory: npm_packages/playwright-odiff
335390
run: npm publish
@@ -342,3 +397,24 @@ jobs:
342397
files: "binaries/*"
343398
env:
344399
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
400+
401+
commit-sanity-check:
402+
runs-on: ubuntu-latest
403+
steps:
404+
- name: Checkout
405+
uses: actions/checkout@v5
406+
407+
- name: Verify binary was not commit in npm package folder
408+
run: |
409+
if ! file ./npm_packages/odiff-bin/bin/odiff.exe | grep -q "Node.js script executable"; then
410+
echo "Looks like you commited a local binary to ./npm_packages/odiff-bin/bin/odiff.exe. Please revert"
411+
exit 1
412+
fi
413+
414+
- name: Check docs in readme
415+
run: |
416+
npm run update-readme
417+
if ! git diff --quiet; then
418+
echo "Please run `npm run update-readme` and commit changes."
419+
exit 1
420+
fi

.valgrind.supp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
zlib_deflate_uninit_hash
3+
Memcheck:Cond
4+
fun:slide_hash
5+
fun:fill_window
6+
fun:deflate_fast
7+
fun:deflate
8+
}
9+
10+
{
11+
zlib_deflate_uninit_value
12+
Memcheck:Value8
13+
fun:slide_hash
14+
fun:fill_window
15+
fun:deflate_fast
16+
fun:deflate
17+
}
18+
19+
{
20+
zlib_deflate_uninit_value_4
21+
Memcheck:Value4
22+
fun:slide_hash
23+
fun:fill_window
24+
fun:deflate_fast
25+
fun:deflate
26+
}

images/diff.png

842 KB
Loading

npm_packages/playwright-odiff/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "playwright-odiff",
3-
"version": "4.3.2",
3+
"version": "4.4.0-beta.1",
44
"description": "Playwright custom matcher using odiff for screenshot comparison",
55
"type": "module",
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
88
"exports": {
99
".": {
10+
"types": "./dist/index.d.ts",
1011
"import": "./dist/index.js",
11-
"types": "./dist/index.d.ts"
12+
"default": "./dist/index.js"
1213
}
1314
},
1415
"scripts": {

npm_packages/playwright-odiff/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { ODiffScreenshotOptions } from "./types";
1+
import type { ODiffScreenshotOptions } from "./types.js";
22

3-
export { toHaveScreenshotOdiff } from "./toHaveScreenshotOdiff";
3+
export { toHaveScreenshotOdiff } from "./toHaveScreenshotOdiff.js";
44
export type { ODiffScreenshotOptions as OdiffScreenshotOptions };
55

66
// Type augmentation for Playwright's expect

npm_packages/playwright-odiff/src/setup.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "@playwright/test";
2-
import { toHaveScreenshotOdiff } from "./toHaveScreenshotOdiff";
3-
import "./types";
2+
import { toHaveScreenshotOdiff } from "./toHaveScreenshotOdiff.js";
3+
import "./types.js";
44

55
expect.extend({
66
toHaveScreenshotOdiff,

npm_packages/playwright-odiff/src/snapshotHelper.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import fs from "fs";
99
import path from "path";
1010
import type { TestInfo, Locator } from "@playwright/test";
11-
import type { ODiffScreenshotOptions, MatcherResult } from "./types";
11+
import type { ODiffScreenshotOptions, MatcherResult } from "./types.js";
1212
import { ODiffOptions } from "odiff-bin";
1313

1414
type NameOrSegments = string | string[];
@@ -269,7 +269,19 @@ export class SnapshotHelper {
269269
return this.createMatcherResult(output.join("\n"), false, log);
270270
}
271271

272-
handleMatching(): MatcherResult {
272+
// because we write screenshots directly to the output path we
273+
// have to simply unlink them on success which is a very fast operation
274+
async handleMatching(): Promise<MatcherResult> {
275+
await Promise.all([
276+
fs.promises.unlink(this.actualPath).catch(() => {}),
277+
fs.promises.unlink(this.previousPath).catch(() => {}),
278+
fs.promises.unlink(this.diffPath).catch(() => {}),
279+
]).catch(() => {});
280+
281+
// Try to remove the test-results directory if it's empty
282+
const testResultsDir = path.dirname(this.actualPath);
283+
await fs.promises.rmdir(testResultsDir).catch(() => {});
284+
273285
return this.createMatcherResult("", true);
274286
}
275287

npm_packages/playwright-odiff/src/toHaveScreenshotOdiff.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import fs from "fs/promises";
22
import fssync from "fs";
33
import path from "path";
44
import type { Page, Locator, TestInfo } from "@playwright/test";
5-
import type { ODiffScreenshotOptions, MatcherResult } from "./types";
5+
import type { ODiffScreenshotOptions, MatcherResult } from "./types.js";
66
import { test } from "@playwright/test";
7-
import { SnapshotHelper } from "./snapshotHelper";
7+
import { SnapshotHelper } from "./snapshotHelper.js";
88
import { ODiffServer } from "odiff-bin";
99

1010
type ODiffServerType = InstanceType<typeof ODiffServer>;
@@ -422,15 +422,14 @@ export async function toHaveScreenshotOdiff(
422422
true,
423423
);
424424
}
425-
return helper.handleMatching();
425+
return await helper.handleMatching();
426426
}
427427

428428
if (
429429
helper.updateSnapshots === "changed" ||
430430
helper.updateSnapshots === "all"
431431
) {
432432
if (result.hasActual) {
433-
// Copy actual to expected (no read/write, just kernel copy)
434433
await fs.copyFile(helper.actualPath, helper.expectedPath);
435434
console.log(helper.expectedPath + " is re-generated, writing actual.");
436435
return helper.createMatcherResult(

npm_packages/playwright-odiff/test/dynamic-content.spec.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ test.describe("toHaveScreenshotOdiff - Dynamic Content", () => {
1111
await page.goto(dynamicPagePath);
1212
await page.waitForLoadState("networkidle");
1313

14-
// Take first screenshot with static content
1514
await expect(page).toHaveScreenshotOdiff("dynamic-first.png");
1615

17-
// Click trigger to update the number
1816
await page.click("#trigger");
17+
await page.waitForTimeout(100);
1918

20-
// Screenshots should be different due to changed number
2119
await expect(page).not.toHaveScreenshotOdiff("dynamic-first.png");
2220
});
2321

npm_packages/playwright-odiff/test/fixtures/dynamic-page.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<!DOCTYPE html>
22
<html lang="en">
3+
34
<head>
45
<meta charset="UTF-8">
56
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -59,6 +60,7 @@
5960
}
6061
</style>
6162
</head>
63+
6264
<body>
6365
<div class="container">
6466
<div class="label">Performance Now</div>
@@ -69,10 +71,14 @@
6971
<script>
7072
function updateNumber() {
7173
document.getElementById('number').textContent = performance.now().toFixed(0);
74+
setInterval(() => {
75+
document.getElementById('number').textContent = performance.now().toFixed(0);
76+
}, 10)
7277
}
7378

7479
// Update number once when trigger button is clicked
7580
document.getElementById('trigger').addEventListener('click', updateNumber);
7681
</script>
7782
</body>
83+
7884
</html>

0 commit comments

Comments
 (0)