Skip to content

Commit c4159b0

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

File tree

11 files changed

+110
-34
lines changed

11 files changed

+110
-34
lines changed

.github/workflows/build.yml

Lines changed: 68 additions & 7 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,48 @@ 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+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \
301+
./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png /tmp/diff-output.png
302+
303+
- name: Run valgrind memcheck - normal mode without diff output
304+
run: |
305+
valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \
306+
./zig-out/bin/odiff test/png/orange.png test/png/orange_changed.png
307+
308+
- name: Run valgrind memcheck - server mode
309+
run: |
310+
timeout 5 valgrind --leak-check=full --show-leak-kinds=all --error-exitcode=1 --errors-for-leak-kinds=definite,possible \
311+
./zig-out/bin/odiff --server || [ $? -eq 124 ]
312+
277313
spellcheck:
278314
name: Spell check
279315
runs-on: ubuntu-latest
280316
steps:
281317
- name: Checkout code
282-
uses: actions/checkout@v4
318+
uses: actions/checkout@v5
283319

284320
- name: Run typos
285321
uses: crate-ci/typos@master
@@ -293,7 +329,7 @@ jobs:
293329
runs-on: ubuntu-latest
294330
steps:
295331
- name: Checkout
296-
uses: actions/checkout@v1
332+
uses: actions/checkout@v5
297333

298334
- name: Download all built binaries
299335
uses: actions/download-artifact@v4
@@ -330,6 +366,10 @@ jobs:
330366
env:
331367
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
332368

369+
- name: Build playwright-odiff package
370+
working-directory: npm_packages/playwright-odiff
371+
run: npm run build
372+
333373
- name: Publish playwright-odiff package
334374
working-directory: npm_packages/playwright-odiff
335375
run: npm publish
@@ -342,3 +382,24 @@ jobs:
342382
files: "binaries/*"
343383
env:
344384
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
385+
386+
commit-sanity-check:
387+
runs-on: ubuntu-latest
388+
steps:
389+
- name: Checkout
390+
uses: actions/checkout@v5
391+
392+
- name: Verify binary was not commit in npm package folder
393+
run: |
394+
if ! file ./npm_packages/odiff-bin/bin/odiff.exe | grep -q "Node.js script executable"; then
395+
echo "Looks like you commited a local binary to ./npm_packages/odiff-bin/bin/odiff.exe. Please revert"
396+
exit 1
397+
fi
398+
399+
- name: Check docs in readme
400+
run: |
401+
npm run update-readme
402+
if ! git diff --quiet; then
403+
echo "Please run `npm run update-readme` and commit changes."
404+
exit 1
405+
fi

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>

npm_packages/playwright-odiff/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// Language and Environment
44
"target": "ES2022",
55
"lib": ["ES2022"],
6-
"module": "ES2022",
6+
"module": "nodenext",
77

88
// Module Resolution
9-
"moduleResolution": "bundler",
9+
"moduleResolution": "nodenext",
1010
"resolveJsonModule": true,
1111
"esModuleInterop": true,
1212
"allowSyntheticDefaultImports": true,

0 commit comments

Comments
 (0)