* 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
87 lines
3.3 KiB
TypeScript
87 lines
3.3 KiB
TypeScript
import { expect, test } from 'bun:test'
|
|
|
|
import { SceneGraph } from '@open-pencil/scene-graph'
|
|
|
|
function graphWithAssignedLabel() {
|
|
const graph = new SceneGraph()
|
|
const page = graph.getPages()[0]
|
|
const component = graph.createNode('COMPONENT', page.id, {
|
|
name: 'NavItem',
|
|
componentPropertyDefinitions: [
|
|
{ id: '207:1', name: 'Label', type: 'TEXT', defaultValue: 'Default' }
|
|
]
|
|
})
|
|
const label = graph.createNode('TEXT', component.id, {
|
|
name: 'Label',
|
|
text: 'Default',
|
|
componentPropertyReferences: [{ propertyId: '207:1', field: 'TEXT' }]
|
|
})
|
|
const instance = graph.createInstance(component.id, page.id)
|
|
if (!instance) throw new Error('Missing instance')
|
|
return { graph, component, label, instance }
|
|
}
|
|
|
|
/**
|
|
* A component states the default for a field a property drives; the enclosing instance's
|
|
* assignment decides the value. Synchronising must not copy the default over it.
|
|
*/
|
|
test('synchronizing leaves a field the enclosing instance assigns alone', () => {
|
|
const { graph, component, instance } = graphWithAssignedLabel()
|
|
const clone = graph.getChildren(instance.id)[0]
|
|
graph.updateNode(instance.id, { componentPropertyAssignments: { '207:1': 'Assigned' } })
|
|
graph.updateNode(clone.id, { text: 'Assigned' })
|
|
|
|
graph.syncInstances(component.id)
|
|
|
|
expect(graph.getNode(clone.id)?.text).toBe('Assigned')
|
|
})
|
|
|
|
test('synchronizing still carries the default to an instance that assigns nothing', () => {
|
|
const { graph, component, label, instance } = graphWithAssignedLabel()
|
|
const clone = graph.getChildren(instance.id)[0]
|
|
|
|
graph.updateNode(label.id, { text: 'Edited default' })
|
|
graph.syncInstances(component.id)
|
|
|
|
expect(graph.getNode(clone.id)?.text).toBe('Edited default')
|
|
})
|
|
|
|
/** Only the referenced field is left alone; the rest of the component edit still lands. */
|
|
test('synchronizing carries other fields of a property-driven layer', () => {
|
|
const { graph, component, label, instance } = graphWithAssignedLabel()
|
|
const clone = graph.getChildren(instance.id)[0]
|
|
graph.updateNode(instance.id, { componentPropertyAssignments: { '207:1': 'Assigned' } })
|
|
graph.updateNode(clone.id, { text: 'Assigned' })
|
|
|
|
graph.updateNode(label.id, { opacity: 0.5 })
|
|
graph.syncInstances(component.id)
|
|
|
|
expect(graph.getNode(clone.id)?.text).toBe('Assigned')
|
|
expect(graph.getNode(clone.id)?.opacity).toBe(0.5)
|
|
})
|
|
|
|
/** Property IDs are document-authored strings, so one may collide with an Object prototype key. */
|
|
test('a property id shared with an Object prototype key is not read as an assignment', () => {
|
|
const graph = new SceneGraph()
|
|
const page = graph.getPages()[0]
|
|
const component = graph.createNode('COMPONENT', page.id, {
|
|
name: 'NavItem',
|
|
componentPropertyDefinitions: [
|
|
{ id: 'toString', name: 'Label', type: 'TEXT', defaultValue: 'Default' }
|
|
]
|
|
})
|
|
const label = graph.createNode('TEXT', component.id, {
|
|
name: 'Label',
|
|
text: 'Default',
|
|
componentPropertyReferences: [{ propertyId: 'toString', field: 'TEXT' }]
|
|
})
|
|
const instance = graph.createInstance(component.id, page.id)
|
|
if (!instance) throw new Error('Missing instance')
|
|
const clone = graph.getChildren(instance.id)[0]
|
|
|
|
graph.updateNode(label.id, { text: 'Edited default' })
|
|
graph.syncInstances(component.id)
|
|
|
|
expect(graph.getNode(clone.id)?.text).toBe('Edited default')
|
|
})
|