Skip to content

Commit 6c8e23e

Browse files
committed
Add debug code
1 parent 807ca94 commit 6c8e23e

File tree

2 files changed

+60
-35
lines changed

2 files changed

+60
-35
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,13 @@ jobs:
280280

281281
- name: Compare pixels
282282
run: .github/scripts/test.sh test-image
283+
- name: List diff folder contents
284+
if: failure()
285+
run: |
286+
echo "=== build/test_images/ ==="
287+
ls -la build/test_images/ 2>/dev/null || echo "(empty or missing)"
288+
echo "=== build/test_images_diff/ ==="
289+
ls -la build/test_images_diff/ 2>/dev/null || echo "(empty or missing)"
283290
- name: IMAGE DIFF DETECTED
284291
if: failure()
285292
run: |

test/image/compare_pixels_test.mjs

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -121,50 +121,68 @@ for (let mockName of allMockList) {
121121
}
122122
console.log('+ test:', mockName);
123123

124-
if (!common.doesFileExist(base)) {
125-
console.error('baseline image missing');
126-
fs.copyFileSync(test, diff);
127-
failed.add(mockName);
128-
continue;
129-
}
130-
131-
const img0 = PNG.sync.read(fs.readFileSync(base));
132-
const img1 = PNG.sync.read(fs.readFileSync(test));
133-
let dimensionMismatch = false;
134-
for (const key of ['height', 'width']) {
135-
const length0 = img0[key];
136-
const length1 = img1[key];
137-
if (length0 !== length1) {
138-
console.error(key + 's do not match: ' + length0 + ' vs ' + length1);
139-
dimensionMismatch = true;
124+
try {
125+
if (!common.doesFileExist(base)) {
126+
console.error('baseline image missing');
127+
fs.copyFileSync(test, diff);
128+
failed.add(mockName);
129+
continue;
140130
}
141-
}
142131

143-
if (dimensionMismatch) {
144-
fs.copyFileSync(test, diff);
145-
failed.add(mockName);
146-
continue;
147-
}
132+
const img0 = PNG.sync.read(fs.readFileSync(base));
133+
const img1 = PNG.sync.read(fs.readFileSync(test));
134+
let dimensionMismatch = false;
135+
for (const key of ['height', 'width']) {
136+
const length0 = img0[key];
137+
const length1 = img1[key];
138+
if (length0 !== length1) {
139+
console.error(key + 's do not match: ' + length0 + ' vs ' + length1);
140+
dimensionMismatch = true;
141+
}
142+
}
148143

149-
if (virtualWebgl) {
150-
if (flakyListVirtualWebgl.has(mockName)) threshold = 0.7;
151-
else threshold = Math.max(0.4, threshold);
152-
}
144+
if (dimensionMismatch) {
145+
fs.copyFileSync(test, diff);
146+
failed.add(mockName);
147+
continue;
148+
}
153149

154-
const { height, width } = img0;
155-
const imageDiff = new PNG({ width, height });
156-
const numDiffPixels = pixelmatch(img0.data, img1.data, imageDiff.data, width, height, { threshold });
150+
if (virtualWebgl) {
151+
if (flakyListVirtualWebgl.has(mockName)) threshold = 0.7;
152+
else threshold = Math.max(0.4, threshold);
153+
}
157154

158-
if (numDiffPixels) {
159-
fs.writeFileSync(diff, PNG.sync.write(imageDiff));
160-
console.error('pixels do not match: ' + numDiffPixels);
155+
const { height, width } = img0;
156+
const imageDiff = new PNG({ width, height });
157+
const numDiffPixels = pixelmatch(img0.data, img1.data, imageDiff.data, width, height, { threshold });
158+
159+
if (numDiffPixels) {
160+
fs.writeFileSync(diff, PNG.sync.write(imageDiff));
161+
console.error('pixels do not match: ' + numDiffPixels);
162+
failed.add(mockName);
163+
} else {
164+
// remove when identical
165+
fs.unlinkSync(test);
166+
}
167+
} catch (e) {
168+
console.error('error comparing ' + mockName + ':', e);
161169
failed.add(mockName);
162-
} else {
163-
// remove when identical
164-
fs.unlinkSync(test);
165170
}
166171
}
167172

173+
// Debug: list contents of diff folder
174+
console.log('\n=== build/test_images/ ===');
175+
try {
176+
const testFiles = fs.readdirSync(constants.pathToTestImages);
177+
console.log(testFiles.length + ' files:', testFiles.join(', '));
178+
} catch { console.log('(empty or missing)'); }
179+
180+
console.log('=== build/test_images_diff/ ===');
181+
try {
182+
const diffFiles = fs.readdirSync(constants.pathToTestImagesDiff);
183+
console.log(diffFiles.length + ' files:', diffFiles.join(', '));
184+
} catch { console.log('(empty or missing)'); }
185+
168186
if (failed.size || skipped.size) {
169187
throw JSON.stringify(
170188
{

0 commit comments

Comments
 (0)