AI-native design editor. Open-source Figma alternative.
test(canvas): verify boolean visual matrix
Danila Poyarkovd48e3e533552
diff --git a/tests/engine/render/canvas/boolean-visual.test.ts b/tests/engine/render/canvas/boolean-visual.test.tsnew file mode 100644index 000000000..a45411dbc--- /dev/null+++ b/tests/engine/render/canvas/boolean-visual.test.ts@@ -0,0 +1,44 @@+import { existsSync } from 'node:fs'++import { describe, expect, test } from 'bun:test'++import { initCanvasKit } from '#cli/headless'++const MATRIX_PATH = '/tmp/open-pencil-boolean-matrix.png'++describe('boolean visual matrix', () => {+ test('generates a non-empty visual fixture for supported shape cases', async () => {+ const proc = Bun.spawnSync({+ cmd: ['bun', 'tests/engine/render/canvas/visual/boolean-matrix.ts'],+ stdout: 'pipe',+ stderr: 'pipe'+ })+ expect(proc.exitCode).toBe(0)+ expect(existsSync(MATRIX_PATH)).toBe(true)++ const ck = await initCanvasKit()+ const bytes = await Bun.file(MATRIX_PATH).arrayBuffer()+ const image = ck.MakeImageFromEncoded(bytes)+ expect(image).not.toBeNull()+ if (!image) return++ expect(image.width()).toBe(720)+ expect(image.height()).toBe(1200)++ const pixels = image.readPixels(0, 0, {+ width: image.width(),+ height: image.height(),+ colorType: ck.ColorType.RGBA_8888,+ alphaType: ck.AlphaType.Unpremul,+ colorSpace: ck.ColorSpace.SRGB+ })+ image.delete()++ let coloredPixels = 0+ for (let i = 0; i < pixels.length; i += 4) {+ const isWhite = pixels[i] > 245 && pixels[i + 1] > 245 && pixels[i + 2] > 245+ if (!isWhite && pixels[i + 3] > 0) coloredPixels+++ }+ expect(coloredPixels).toBeGreaterThan(20_000)+ })+})