Skip to content

Commit 83c871c

Browse files
authored
Merge pull request #7653 from Vaivaswat2244/7618
Adding Visual Test Report in Github Actions
2 parents 75cace3 + 91f1e98 commit 83c871c

File tree

8 files changed

+463
-7
lines changed

8 files changed

+463
-7
lines changed

.github/workflows/ci-test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,23 @@ jobs:
2424
env:
2525
CI: true
2626
- name: build and test
27+
id: test
2728
run: npm test
29+
continue-on-error: true
2830
env:
2931
CI: true
32+
- name: Generate Visual Test Report
33+
if: always()
34+
run: node visual-report.js
35+
env:
36+
CI: true
37+
- name: Upload Visual Test Report
38+
if: always()
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: visual-test-report
42+
path: test/unit/visual/visual-report.html
43+
retention-days: 14
3044
- name: generate TypeScript types
3145
run: npm run generate-types
3246
env:
@@ -36,6 +50,10 @@ jobs:
3650
env:
3751
CI: true
3852
- name: report test coverage
53+
if: steps.test.outcome == 'success'
3954
run: bash <(curl -s https://codecov.io/bash) -f coverage/coverage-final.json
4055
env:
4156
CI: true
57+
- name: fail job if tests failed
58+
if: steps.test.outcome != 'success'
59+
run: exit 1

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,17 @@ __screenshots__/
2424
*.d.ts
2525
p5.zip
2626
yarn.lock
27+
28+
docs/data.json
29+
analyzer/
30+
preview/
31+
__screenshots__/
32+
actual-screenshots/
33+
visual-report.html
34+
2735
todo.md
2836

2937
*.DS_Store
3038
.idea
31-
.project
39+
.project
40+
Binary file not shown.

test/unit/visual/screenshots/Shape drawing/2D mode/Drawing triangles/metadata.json

Lines changed: 0 additions & 3 deletions
This file was deleted.
Binary file not shown.

test/unit/visual/screenshots/Shape drawing/WebGL mode/Drawing triangles/metadata.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/unit/visual/visualTest.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,15 @@ export function visualTest(
463463
: [];
464464

465465
for (let i = 0; i < actual.length; i++) {
466+
const flatName = name.replace(/\//g, '-');
467+
const actualFilename = `../actual-screenshots/${flatName}-${i.toString().padStart(3, '0')}.png`;
466468
if (expected[i]) {
467469
const result = await checkMatch(actual[i], expected[i], myp5);
470+
// Always save the actual image before potentially throwing an error
471+
writeImageFile(actualFilename, toBase64(actual[i]));
468472
if (!result.ok) {
473+
const diffFilename = `../actual-screenshots/${flatName}-${i.toString().padStart(3, '0')}-diff.png`;
474+
writeImageFile(diffFilename, toBase64(result.diff));
469475
throw new Error(
470476
`Screenshots do not match! Expected:\n${toBase64(expected[i])}\n\nReceived:\n${toBase64(actual[i])}\n\nDiff:\n${toBase64(result.diff)}\n\n` +
471477
'If this is unexpected, paste these URLs into your browser to inspect them.\n\n' +
@@ -474,6 +480,7 @@ export function visualTest(
474480
}
475481
} else {
476482
writeImageFile(expectedFilenames[i], toBase64(actual[i]));
483+
writeImageFile(actualFilename, toBase64(actual[i]));
477484
}
478485
}
479486
});

0 commit comments

Comments
 (0)