* 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
150 lines
5.3 KiB
TypeScript
150 lines
5.3 KiB
TypeScript
import { test, expect } from '@playwright/test'
|
|
|
|
import { CanvasHelper } from '#tests/helpers/canvas'
|
|
|
|
const NODE_COUNT = 5000
|
|
|
|
test('large layer trees stay virtualized and scrollable', async ({ page }) => {
|
|
const canvas = new CanvasHelper(page)
|
|
await page.goto('/?test&no-rulers')
|
|
await canvas.waitForInit()
|
|
|
|
const replaceStartedAt = await page.evaluate((count: number) => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
|
|
const activeGraph = store.graph
|
|
const Graph = activeGraph.constructor as new () => typeof activeGraph
|
|
const graph = new Graph()
|
|
const pageId = graph.getPages()[0]?.id
|
|
if (!pageId) throw new Error('Page not initialized')
|
|
for (let i = 0; i < count; i++) {
|
|
graph.createNode('RECTANGLE', pageId, {
|
|
name: `Layer ${String(i + 1).padStart(4, '0')}`,
|
|
x: (i % 40) * 24,
|
|
y: Math.floor(i / 40) * 24,
|
|
width: 16,
|
|
height: 16,
|
|
fills: [
|
|
{
|
|
type: 'SOLID',
|
|
color: { r: 0.2, g: 0.5, b: 0.9, a: 1 },
|
|
visible: true,
|
|
opacity: 1
|
|
}
|
|
]
|
|
})
|
|
}
|
|
const startedAt = performance.now()
|
|
store.replaceGraph(graph)
|
|
return startedAt
|
|
}, NODE_COUNT)
|
|
|
|
await canvas.waitForRender()
|
|
|
|
const scroller = page.getByTestId('layers-scroll')
|
|
const rows = page.getByTestId('layers-item')
|
|
|
|
await expect(rows.first()).toContainText('Layer 0001')
|
|
await expect.poll(() => rows.count()).toBeLessThan(250)
|
|
await expect
|
|
.poll(() => page.evaluate((startedAt) => performance.now() - startedAt, replaceStartedAt))
|
|
.toBeLessThan(5000)
|
|
|
|
await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
const pageNode = store.graph.getNode(store.state.currentPageId)
|
|
const lastId = pageNode?.childIds.at(-1)
|
|
if (!lastId) throw new Error('Last layer not found')
|
|
store.select([lastId])
|
|
})
|
|
|
|
const lastRow = rows.filter({ hasText: 'Layer 5000' }).first()
|
|
await expect(lastRow).toBeVisible()
|
|
const scrollBefore = await scroller.evaluate((el) => el.scrollTop)
|
|
|
|
await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
|
|
const pageNode = store.graph.getNode(store.state.currentPageId)
|
|
const firstId = pageNode?.childIds[0]
|
|
if (!firstId) throw new Error('First layer not found')
|
|
store.updateNodeWithUndo(firstId, { x: 32 }, 'Move first layer')
|
|
})
|
|
|
|
await expect(lastRow).toBeVisible()
|
|
await page.evaluate(
|
|
() =>
|
|
new Promise<void>((resolve) => {
|
|
requestAnimationFrame(() => resolve())
|
|
})
|
|
)
|
|
await expect.poll(() => scroller.evaluate((el) => el.scrollTop)).toBe(scrollBefore)
|
|
|
|
await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
|
|
const pageNode = store.graph.getNode(store.state.currentPageId)
|
|
const lastId = pageNode?.childIds.at(-1)
|
|
if (!lastId) throw new Error('Last layer not found')
|
|
store.renameNode(lastId, 'Last layer renamed')
|
|
})
|
|
|
|
const renamedRow = rows.filter({ hasText: 'Last layer renamed' }).first()
|
|
await expect(renamedRow).toBeVisible()
|
|
await renamedRow.dblclick()
|
|
const renameInput = page.getByTestId('layers-item-input')
|
|
await expect(renameInput).toBeFocused()
|
|
|
|
await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
const firstId = store.graph.getNode(store.state.currentPageId)?.childIds[0]
|
|
if (!firstId) throw new Error('First layer not found')
|
|
store.updateNodeWithUndo(firstId, { y: 48 }, 'Move first layer again')
|
|
})
|
|
|
|
await expect(renameInput).toBeFocused()
|
|
})
|
|
|
|
test('layer tree supports range and additive selection', async ({ page }) => {
|
|
const canvas = new CanvasHelper(page)
|
|
await page.goto('/?test&no-rulers')
|
|
await canvas.waitForInit()
|
|
|
|
await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
const activeGraph = store.graph
|
|
const Graph = activeGraph.constructor as new () => typeof activeGraph
|
|
const graph = new Graph()
|
|
const pageId = graph.getPages()[0]?.id
|
|
if (!pageId) throw new Error('Page not initialized')
|
|
for (let index = 1; index <= 8; index++) {
|
|
graph.createNode('RECTANGLE', pageId, { name: `Layer ${index}` })
|
|
}
|
|
store.replaceGraph(graph)
|
|
})
|
|
|
|
const rows = page.getByTestId('layers-item')
|
|
await rows.filter({ hasText: 'Layer 2' }).click()
|
|
await page.keyboard.down('Shift')
|
|
await rows.filter({ hasText: 'Layer 5' }).click()
|
|
await page.keyboard.up('Shift')
|
|
|
|
const selectedRows = page.getByTestId('layers-item').and(page.locator('[data-selected]'))
|
|
await expect(selectedRows).toHaveCount(4)
|
|
await expect(rows.filter({ hasText: 'Layer 2' })).toHaveAttribute('data-selected')
|
|
await expect(rows.filter({ hasText: 'Layer 5' })).toHaveAttribute('data-selected')
|
|
|
|
await page.keyboard.down('Meta')
|
|
await rows.filter({ hasText: 'Layer 7' }).click()
|
|
await page.keyboard.up('Meta')
|
|
|
|
await expect(selectedRows).toHaveCount(5)
|
|
await expect(rows.filter({ hasText: 'Layer 7' })).toHaveAttribute('data-selected')
|
|
})
|