* 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
62 lines
2.7 KiB
TypeScript
62 lines
2.7 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { FigmaAPI } from '@open-pencil/core'
|
|
import { exportFigFile, parseFigFile } from '@open-pencil/core/io'
|
|
import { initCodec } from '@open-pencil/core/kiwi'
|
|
import { SceneGraph } from '@open-pencil/scene-graph'
|
|
|
|
const BLUE = { r: 0, g: 0, b: 1, a: 1 }
|
|
const RED = { r: 1, g: 0, b: 0, a: 1 }
|
|
|
|
function findInstanceAndVector(graph: SceneGraph) {
|
|
const instance = [...graph.getAllNodes()].find((n) => n.type === 'INSTANCE')
|
|
if (!instance) throw new Error('instance not found')
|
|
const vector = graph.getChildren(instance.id)[0]
|
|
return { instance, vector }
|
|
}
|
|
|
|
describe('re-editing an instance fill across multiple save/reload cycles', () => {
|
|
test('a second live edit overrides the first, not the other way around', async () => {
|
|
await initCodec()
|
|
|
|
const graph = new SceneGraph()
|
|
const page = graph.getPages()[0]
|
|
const icon = graph.createNode('COMPONENT', page.id, { name: 'Icon' })
|
|
graph.createNode('VECTOR', icon.id, {
|
|
name: 'path',
|
|
width: 16,
|
|
height: 16,
|
|
fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, opacity: 1, visible: true }]
|
|
})
|
|
|
|
const instance = graph.createInstance(icon.id, page.id)
|
|
if (!instance) throw new Error('failed to create instance')
|
|
const figma1 = new FigmaAPI(graph)
|
|
const vectorProxy1 = figma1.getNodeById(graph.getChildren(instance.id)[0].id)
|
|
if (!vectorProxy1) throw new Error('vector proxy not found')
|
|
vectorProxy1.fills = [{ type: 'SOLID', color: BLUE, opacity: 1, visible: true }]
|
|
|
|
// Round 1: export the blue edit, reimport it — this is the state a
|
|
// freshly-reopened file would be in, with `blue` baked into the stored
|
|
// symbolOverride but no live `overrides` bookkeeping (per §1 of the fix).
|
|
const bytes1 = await exportFigFile(graph)
|
|
const graph2 = await parseFigFile(bytes1.buffer as ArrayBuffer)
|
|
const { vector: vector2 } = findInstanceAndVector(graph2)
|
|
expect(vector2.fills[0]?.color).toEqual(BLUE)
|
|
|
|
// Round 2: live-edit the reimported instance's icon to red, then export
|
|
// and reimport again. Without the fix, `applySymbolOverrides` reapplies
|
|
// the STALE stored (blue) override on this same export pass, silently
|
|
// discarding the fresh (red) edit.
|
|
const figma2 = new FigmaAPI(graph2)
|
|
const vectorProxy2 = figma2.getNodeById(vector2.id)
|
|
if (!vectorProxy2) throw new Error('vector proxy not found')
|
|
vectorProxy2.fills = [{ type: 'SOLID', color: RED, opacity: 1, visible: true }]
|
|
|
|
const bytes2 = await exportFigFile(graph2)
|
|
const graph3 = await parseFigFile(bytes2.buffer as ArrayBuffer)
|
|
const { vector: vector3 } = findInstanceAndVector(graph3)
|
|
expect(vector3.fills[0]?.color).toEqual(RED)
|
|
})
|
|
})
|