openpencil/tests/e2e/canvas/stroke-paint-visual.spec.ts
Danila Poyarkov aa86873dd7
test: typecheck the test suites and fix what that found (#896)
* build: typecheck the test suites

Tests were in no TypeScript program: no tsconfig included tests/** or
packages/*/tests/**, and bun strips types without checking them, so a
fixture could drop a required field and keep passing until something
read it.

@types/bun moves to the root because it was installed per package only,
and #cli-tests/* joins the paths the root config already carries.

* test: fix the type errors the test suites were hiding

Typechecking the tests turned up 1123 errors. Most were ordinary
strictness, but some were real: `NodeChange` bound to Figma's plugin
typings rather than the Kiwi codec in thirteen .fig tests,
materializeInstance was called with six arguments against five so the
blobs and source children were dropped, CanvasKit pixels were written
to a plain object that never reached WASM, and assertions were made
through accessors that do not exist, so they asserted nothing.

Fixtures that had quietly lost a required field now carry it, nullable
results are narrowed through the existing expectDefined helper rather
than assumed, and stand-ins for CanvasKit and the editor go through one
named helper instead of an unexplained cast at each site.

No test was deleted, skipped, or weakened, and no `any`, non-null
assertion, or ts-expect-error was introduced.

* docs: record what typechecking the tests established

Pins the app program's global types with an assertion rather than a
note, since an unpinned types list lets any root @types package decide
which platform src/** is judged against.

The two environment faults that look like code regressions — Vite's
dependency pre-bundle outliving a package rebuild, and heavy .fig
suites failing under load — go to the development docs, where an
explanation belongs.

* fix: align @types/bun and keep node types resolvable when extended

The root manifest declared a newer @types/bun than every package, which
check:monorepo rejects, and pinning the app program's types left them
unresolvable from a config that extends this one out of tree.

* fix: fail the test typecheck when the compiler itself fails

The gate matched diagnostics by substring, so a compiler or config
failure that named no test file printed a pass while having checked
nothing. Diagnostics are now split by whether they name a file: an
unscoped one is the run failing and stops the gate, a test file's is a
finding, and a source file's stays out by design.

Also drops the parameter planComponentConstruction never read, and
makes the inner-shadow verification script exit non-zero when it
renders no image instead of logging and succeeding.

* chore: merge master into tests-typecheck
2026-10-05 12:42:38 +00:00

119 lines
3.6 KiB
TypeScript

import type { StrokeCap } from '@open-pencil/scene-graph'
import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
/**
* A gradient stroke used to draw opaque black, because a stroke could only hold one color.
* The strokes are heavy so the ring crosses each gradient's falloff: a radial or diamond
* gradient is near-uniform at a node's perimeter, so a thin ring would not tell them apart.
*/
test('gradient strokes', 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 stops = [
{ color: { r: 0.96, g: 0.35, b: 0.12, a: 1 }, position: 0 },
{ color: { r: 0.23, g: 0.51, b: 0.96, a: 1 }, position: 1 }
]
const kinds = [
'GRADIENT_LINEAR',
'GRADIENT_RADIAL',
'GRADIENT_ANGULAR',
'GRADIENT_DIAMOND'
] as const
for (const [index, type] of kinds.entries()) {
store.graph.createNode('RECTANGLE', pageId, {
name: `${type} stroke visual`,
x: 70 + index * 200,
y: 80,
width: 130,
height: 130,
fills: [],
strokes: [
{
type,
color: { r: 0, g: 0, b: 0, a: 1 },
gradientStops: stops,
gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 },
weight: 44,
visible: true,
opacity: 1,
align: 'CENTER'
}
]
})
}
// A solid stroke beside them must be unaffected by the shader the others set.
store.graph.createNode('RECTANGLE', pageId, {
name: 'solid stroke visual',
x: 70,
y: 260,
width: 130,
height: 130,
fills: [],
strokes: [
{
type: 'SOLID',
color: { r: 0.13, g: 0.72, b: 0.33, a: 1 },
weight: 16,
visible: true,
opacity: 1,
align: 'CENTER'
}
]
})
// Vector strokes draw through a different path: dashed ones stroke the path, undashed ones
// fill an outline with fillPaint, and arrowheads are filled shapes of their own.
const vectorStroke = (extra: Record<string, unknown>) => ({
type: 'GRADIENT_LINEAR' as const,
color: { r: 0, g: 0, b: 0, a: 1 },
gradientStops: stops,
gradientTransform: { m00: 1, m01: 0, m02: 0, m10: 0, m11: 1, m12: 0 },
weight: 18,
visible: true,
opacity: 1,
align: 'CENTER' as const,
...extra
})
const lines: Array<{ dashPattern?: number[]; cap?: StrokeCap }> = [
{},
{ dashPattern: [24, 12] },
{ cap: 'ARROW_EQUILATERAL' }
]
for (const [index, extra] of lines.entries()) {
store.graph.createNode('VECTOR', pageId, {
name: `vector gradient stroke ${index}`,
x: 300,
y: 260 + index * 70,
width: 260,
height: 1,
strokeCap: extra.cap ?? 'NONE',
vectorNetwork: {
vertices: [
{ x: 0, y: 0 },
{ x: 260, y: 0 }
],
segments: [
{ start: 0, end: 1, tangentStart: { x: 0, y: 0 }, tangentEnd: { x: 0, y: 0 } }
],
regions: []
},
fills: [],
strokes: [vectorStroke(extra)]
})
}
store.clearSelection()
store.requestRender()
})
await editor.canvas.waitForRender()
editor.canvas.assertNoErrors()
const buffer = await editor.canvas.screenshotCanvasRegion()
expect(buffer).toMatchSnapshot('gradient-strokes.png')
})