Skip to content

AI-native design editor. Open-source Figma alternative.

test(canvas): cover renderer showcase visuals

Danila Poyarkovf8db73949ed9
diff --git a/AGENTS.md b/AGENTS.md
index 0fd6c8d3a..65fa6e843 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -308,6 +308,7 @@ Self-review checklist:
- Section/frame title text never scales — render at fixed font size, ellipsize to fit
- Rulers are rendered on the canvas (not DOM), with selection range badges that don't overlap tick numbers
- Remote cursors: Figma-style colored arrows with white border + name pill, rendered in screen space
+- Pixel-affecting renderer features need committed visual coverage, not just mock/geometry assertions. Add or update a Playwright canvas snapshot for changes to fills, gradients, images, blend modes, masks, boolean geometry, corners, strokes, shadows, blur, text rendering, or demo showcase scenes. Use targeted snapshot updates such as `bunx playwright test tests/e2e/canvas/renderer-visuals.spec.ts --project=openpencil --update-snapshots` and then rerun the same test without `--update-snapshots`.
## Scene graph
diff --git a/tests/e2e/canvas/demo-effects.spec.ts b/tests/e2e/canvas/demo-effects.spec.ts
new file mode 100644
index 000000000..076def653
--- /dev/null
+++ b/tests/e2e/canvas/demo-effects.spec.ts
@@ -0,0 +1,23 @@
+import { expect, test, useEditorSetup } from '#tests/e2e/fixtures'
+
+const editor = useEditorSetup('/demo?test&no-chrome&no-rulers')
+
+async function expectCanvas(name: string) {
+ editor.canvas.assertNoErrors()
+ const buffer = await editor.canvas.canvas.screenshot()
+ expect(buffer).toMatchSnapshot(`${name}.png`)
+}
+
+test('demo effects section showcases renderer features', async () => {
+ await editor.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ store.state.zoom = 0.82
+ store.state.panX = 8
+ store.state.panY = -556
+ store.clearSelection()
+ store.requestRender()
+ })
+ await editor.canvas.waitForRender()
+ await expectCanvas('demo-effects-section')
+})
diff --git a/tests/e2e/canvas/demo-effects.spec.ts-snapshots/demo-effects-section-openpencil-darwin.png b/tests/e2e/canvas/demo-effects.spec.ts-snapshots/demo-effects-section-openpencil-darwin.png
new file mode 100644
index 000000000..504c7fc10
Binary files /dev/null and b/tests/e2e/canvas/demo-effects.spec.ts-snapshots/demo-effects-section-openpencil-darwin.png differ
diff --git a/tests/e2e/canvas/renderer-visuals.spec.ts b/tests/e2e/canvas/renderer-visuals.spec.ts
new file mode 100644
index 000000000..e7bea16a4
--- /dev/null
+++ b/tests/e2e/canvas/renderer-visuals.spec.ts
@@ -0,0 +1,168 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+
+const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
+
+async function expectCanvas(name: string) {
+ editor.canvas.assertNoErrors()
+ const buffer = await editor.canvas.canvas.screenshot()
+ expect(buffer).toMatchSnapshot(`${name}.png`)
+}
+
+test('boolean operations', async () => {
+ await editor.page.evaluate(() => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const pageId = store.state.currentPageId
+ const operations = ['UNION', 'SUBTRACT', 'INTERSECT', 'EXCLUDE'] as const
+ const colors = [
+ { r: 0.23, g: 0.51, b: 0.96, a: 1 },
+ { r: 0.96, g: 0.35, b: 0.35, a: 1 },
+ { r: 0.08, g: 0.73, b: 0.73, a: 1 },
+ { r: 0.58, g: 0.27, b: 0.95, a: 1 }
+ ]
+
+ for (const [index, operation] of operations.entries()) {
+ const group = store.graph.createNode('BOOLEAN_OPERATION', pageId, {
+ name: `${operation} visual`,
+ x: 72 + index * 152,
+ y: 92,
+ width: 124,
+ height: 104,
+ booleanOperation: operation,
+ fills: [{ type: 'SOLID', color: colors[index], visible: true, opacity: 1 }],
+ strokes: [
+ {
+ color: { r: 0.08, g: 0.1, b: 0.18, a: 0.32 },
+ weight: 2,
+ visible: true,
+ opacity: 1,
+ align: 'CENTER'
+ }
+ ]
+ })
+ store.graph.createNode('RECTANGLE', group.id, {
+ name: `${operation} rectangle`,
+ x: 0,
+ y: 18,
+ width: 82,
+ height: 70,
+ cornerRadius: 14
+ })
+ store.graph.createNode('ELLIPSE', group.id, {
+ name: `${operation} ellipse`,
+ x: 42,
+ y: 0,
+ width: 82,
+ height: 104
+ })
+ }
+
+ store.clearSelection()
+ store.requestRender()
+ })
+ await editor.canvas.waitForRender()
+ await expectCanvas('boolean-operations')
+})
+
+test('gradients and image fill modes', async () => {
+ await editor.page.evaluate(async () => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ const pageId = store.state.currentPageId
+
+ const imageCanvas = document.createElement('canvas')
+ imageCanvas.width = 48
+ imageCanvas.height = 32
+ const ctx = imageCanvas.getContext('2d')
+ if (!ctx) throw new Error('Cannot create image fixture canvas')
+ ctx.fillStyle = '#ef4444'
+ ctx.fillRect(0, 0, 24, 16)
+ ctx.fillStyle = '#3b82f6'
+ ctx.fillRect(24, 0, 24, 16)
+ ctx.fillStyle = '#14b8a6'
+ ctx.fillRect(0, 16, 24, 16)
+ ctx.fillStyle = '#facc15'
+ ctx.fillRect(24, 16, 24, 16)
+ ctx.strokeStyle = '#111827'
+ ctx.lineWidth = 3
+ ctx.strokeRect(1.5, 1.5, 45, 29)
+ const blob = await new Promise<Blob>((resolve, reject) => {
+ imageCanvas.toBlob((result) => {
+ if (result) {
+ resolve(result)
+ return
+ }
+ reject(new Error('Failed to encode image fixture'))
+ }, 'image/png')
+ })
+ const imageHash = store.storeImage(new Uint8Array(await blob.arrayBuffer()))
+
+ store.graph.createNode('FRAME', pageId, {
+ name: 'Gradient and Image Backdrop',
+ x: 56,
+ y: 52,
+ width: 700,
+ height: 250,
+ cornerRadius: 22,
+ fills: [{ type: 'SOLID', color: { r: 0.95, g: 0.95, b: 0.97, a: 1 }, visible: true, opacity: 1 }]
+ })
+
+ const gradientStops = [
+ { color: { r: 0.23, g: 0.51, b: 0.96, a: 1 }, position: 0 },
+ { color: { r: 0.58, g: 0.27, b: 0.95, a: 1 }, position: 0.55 },
+ { color: { r: 0.08, g: 0.73, b: 0.73, a: 1 }, position: 1 }
+ ]
+ const gradientTypes = ['GRADIENT_LINEAR', 'GRADIENT_RADIAL', 'GRADIENT_ANGULAR', 'GRADIENT_DIAMOND'] as const
+ for (const [index, type] of gradientTypes.entries()) {
+ store.graph.createNode('RECTANGLE', pageId, {
+ name: `${type} visual`,
+ x: 84 + index * 116,
+ y: 84,
+ width: 92,
+ height: 72,
+ cornerRadius: 16,
+ fills: [{ type, color: { r: 0, g: 0, b: 0, a: 1 }, visible: true, opacity: 1, gradientStops }]
+ })
+ }
+
+ const scaleModes = ['FILL', 'FIT', 'TILE', 'CROP'] as const
+ for (const [index, imageScaleMode] of scaleModes.entries()) {
+ store.graph.createNode('RECTANGLE', pageId, {
+ name: `${imageScaleMode} image visual`,
+ x: 84 + index * 116,
+ y: 184,
+ width: 92,
+ height: 72,
+ cornerRadius: 14,
+ fills: [
+ {
+ type: 'IMAGE',
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ visible: true,
+ opacity: 1,
+ imageHash,
+ imageScaleMode,
+ imageTransform:
+ imageScaleMode === 'CROP'
+ ? { m00: 0.5, m01: 0, m02: 0.25, m10: 0, m11: 0.5, m12: 0.25 }
+ : undefined
+ }
+ ],
+ strokes: [
+ {
+ color: { r: 1, g: 1, b: 1, a: 0.9 },
+ weight: 2,
+ visible: true,
+ opacity: 1,
+ align: 'INSIDE'
+ }
+ ]
+ })
+ }
+
+ store.clearSelection()
+ store.requestRender()
+ })
+ await editor.canvas.waitForRender()
+ await expectCanvas('gradients-and-image-fill-modes')
+})
diff --git a/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/boolean-operations-openpencil-darwin.png b/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/boolean-operations-openpencil-darwin.png
new file mode 100644
index 000000000..b617255ab
Binary files /dev/null and b/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/boolean-operations-openpencil-darwin.png differ
diff --git a/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/gradients-and-image-fill-modes-openpencil-darwin.png b/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/gradients-and-image-fill-modes-openpencil-darwin.png
new file mode 100644
index 000000000..7c24d14e6
Binary files /dev/null and b/tests/e2e/canvas/renderer-visuals.spec.ts-snapshots/gradients-and-image-fill-modes-openpencil-darwin.png differ