Skip to content

Commit 24ffe88

Browse files
committed
Revert "Try using pixelmatch for testing"
This reverts commit 2cb6a0a.
1 parent 2cb6a0a commit 24ffe88

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

package-lock.json

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

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
"i18next-browser-languagedetector": "^4.0.1",
5353
"lint-staged": "^15.1.0",
5454
"msw": "^2.6.3",
55-
"pixelmatch": "^6.0.0",
5655
"rollup": "^4.9.6",
5756
"rollup-plugin-string": "^3.0.0",
5857
"rollup-plugin-visualizer": "^5.12.0",

test/unit/visual/visualTest.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import p5 from '../../../src/app.js';
22
import { server } from '@vitest/browser/context'
3-
import pixelmatch from 'pixelmatch'
43
import { THRESHOLD, DIFFERENCE, ERODE } from '../../../src/core/constants.js';
54
const { readFile, writeFile } = server.commands
65

@@ -105,22 +104,39 @@ export async function checkMatch(actual, expected, p5) {
105104
);
106105
}
107106

108-
const diffData = actual.drawingContext.createImageData(actual.width, actual.height);
109-
const diffCount = pixelmatch(
110-
actual.drawingContext.getImageData(0, 0, actual.width, actual.height).data,
111-
expected.drawingContext.getImageData(0, 0, actual.width, actual.height).data,
112-
diffData.data,
113-
actual.width,
114-
actual.height,
115-
{ threshold: 0.4 }
116-
);
107+
const expectedWithBg = p5.createGraphics(expected.width, expected.height);
108+
expectedWithBg.pixelDensity(1);
109+
expectedWithBg.background(BG);
110+
expectedWithBg.image(expected, 0, 0);
117111

118112
const cnv = p5.createGraphics(actual.width, actual.height);
119-
cnv.drawingContext.putImageData(diffData, 0, 0)
120-
const diff = cnv.get()
113+
cnv.pixelDensity(1);
114+
cnv.background(BG);
115+
cnv.image(actual, 0, 0);
116+
cnv.blendMode(DIFFERENCE);
117+
cnv.image(expectedWithBg, 0, 0);
118+
for (let i = 0; i < shiftThreshold; i++) {
119+
cnv.filter(ERODE, false);
120+
}
121+
const diff = cnv.get();
121122
cnv.remove();
123+
diff.loadPixels();
124+
expectedWithBg.remove();
125+
126+
let ok = true;
127+
for (let i = 0; i < diff.pixels.length; i += 4) {
128+
let diffSum = 0;
129+
for (let off = 0; off < 3; off++) {
130+
diffSum += diff.pixels[i+off]
131+
}
132+
diffSum /= 3;
133+
if (diffSum > COLOR_THRESHOLD) {
134+
ok = false;
135+
break;
136+
}
137+
}
122138

123-
return { ok: diffCount === 0, diff };
139+
return { ok, diff };
124140
}
125141

126142
/**

0 commit comments

Comments
 (0)