openpencil/tests/engine/figma/api/serialization.test.ts
Danila Poyarkov 1ed7de6056 chore(lint): reject broad unknown type assertions
- Add AST-based lint checks for broad unknown object assertions and local JsonObject aliases
- Centralize JsonObject in core and package-local MCP RPC JSON typing
- Replace baseline Record<string, unknown> assertions with named shared/domain types
2026-05-25 00:26:02 +03:00

40 lines
1.1 KiB
TypeScript

import { describe, expect, test } from 'bun:test'
import { createAPI } from './helpers'
interface SerializedNodeWithChildren {
children?: unknown[]
}
describe('serialization', () => {
test('toJSON returns clean object', () => {
const api = createAPI()
const frame = api.createFrame()
frame.name = 'Card'
frame.resize(300, 200)
frame.fills = [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, opacity: 1, visible: true }]
const json = frame.toJSON()
expect(json.name).toBe('Card')
expect(json.width).toBe(300)
expect(json.fills).toBeDefined()
})
test('toJSON includes children', () => {
const api = createAPI()
const frame = api.createFrame()
const rect = api.createRectangle()
frame.appendChild(rect)
const json = frame.toJSON() as SerializedNodeWithChildren
expect(json.children).toBeDefined()
expect(json.children?.length).toBe(1)
})
test('toString returns readable string', () => {
const api = createAPI()
const frame = api.createFrame()
frame.name = 'Card'
expect(frame.toString()).toContain('FRAME')
expect(frame.toString()).toContain('Card')
})
})