* 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
92 lines
3.1 KiB
TypeScript
92 lines
3.1 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { FigmaAPI, SceneGraph } from '@open-pencil/core'
|
|
import {
|
|
analyzeOverlaps,
|
|
computeOverlaps,
|
|
findPageId,
|
|
type AnalyzeOverlapsResult
|
|
} from '@open-pencil/core/tools/analyze/overlaps'
|
|
|
|
import { pageId, rect } from './helpers'
|
|
|
|
describe('analyze overlaps page scope', () => {
|
|
test('default scope limits analysis to a single page', () => {
|
|
const graph = new SceneGraph()
|
|
const page1 = pageId(graph)
|
|
const page2 = graph.addPage('Page 2')
|
|
|
|
rect(graph, 'A', page1, 0, 0, 100, 100)
|
|
rect(graph, 'B', page1, 50, 50, 100, 100)
|
|
rect(graph, 'C', page2.id, 0, 0, 100, 100)
|
|
rect(graph, 'D', page2.id, 50, 50, 100, 100)
|
|
|
|
const result = computeOverlaps(graph)
|
|
expect(result.summary.overlapCount).toBe(1)
|
|
expect(result.overlaps).toHaveLength(1)
|
|
expect(
|
|
result.overlaps.every((o) => {
|
|
const nodeA = graph.getNode(o.nodeA.id)
|
|
const nodeB = graph.getNode(o.nodeB.id)
|
|
if (!nodeA || !nodeB) return false
|
|
return findPageId(graph, nodeA) === page1 && findPageId(graph, nodeB) === page1
|
|
})
|
|
).toBe(true)
|
|
})
|
|
|
|
test('missing page name returns an empty result', () => {
|
|
const graph = new SceneGraph()
|
|
const page1 = pageId(graph)
|
|
const page2 = graph.addPage('Page 2')
|
|
|
|
rect(graph, 'A', page1, 0, 0, 100, 100)
|
|
rect(graph, 'B', page1, 50, 50, 100, 100)
|
|
rect(graph, 'C', page2.id, 0, 0, 100, 100)
|
|
rect(graph, 'D', page2.id, 50, 50, 100, 100)
|
|
|
|
const result = computeOverlaps(graph, { page: 'Missing' })
|
|
expect(result.summary.totalNodes).toBe(0)
|
|
expect(result.summary.analyzedNodes).toBe(0)
|
|
expect(result.summary.overlapCount).toBe(0)
|
|
expect(result.overlaps).toHaveLength(0)
|
|
})
|
|
|
|
test('ToolDef currentPage default uses page ID so duplicate page names do not leak', () => {
|
|
const graph = new SceneGraph()
|
|
const page1 = pageId(graph)
|
|
const page2 = graph.addPage('Page 1')
|
|
|
|
rect(graph, 'A', page2.id, 0, 0, 100, 100)
|
|
rect(graph, 'B', page2.id, 50, 50, 100, 100)
|
|
|
|
const api = new FigmaAPI(graph)
|
|
expect(api.currentPageId).toBe(page1)
|
|
|
|
const defaultResult = analyzeOverlaps.execute(api, {}) as AnalyzeOverlapsResult
|
|
expect(defaultResult.summary.overlapCount).toBe(0)
|
|
expect(defaultResult.overlaps).toHaveLength(0)
|
|
|
|
api.currentPage = api.wrapNode(page2.id)
|
|
const currentResult = analyzeOverlaps.execute(api, {}) as AnalyzeOverlapsResult
|
|
expect(currentResult.summary.overlapCount).toBeGreaterThan(0)
|
|
})
|
|
|
|
test('page_id argument disambiguates duplicate page names', () => {
|
|
const graph = new SceneGraph()
|
|
const page1 = pageId(graph)
|
|
const page2 = graph.addPage('Page 1')
|
|
|
|
rect(graph, 'A', page2.id, 0, 0, 100, 100)
|
|
rect(graph, 'B', page2.id, 50, 50, 100, 100)
|
|
|
|
const byId = computeOverlaps(graph, { page_id: page2.id })
|
|
expect(byId.summary.overlapCount).toBe(1)
|
|
|
|
const byName = computeOverlaps(graph, { page: 'Page 1' })
|
|
expect(byName.summary.overlapCount).toBe(0)
|
|
|
|
const byFirstPage = computeOverlaps(graph, { page_id: page1 })
|
|
expect(byFirstPage.summary.overlapCount).toBe(0)
|
|
})
|
|
})
|