* 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
149 lines
4.5 KiB
TypeScript
149 lines
4.5 KiB
TypeScript
import { test, expect, type Page } from '@playwright/test'
|
|
|
|
import { CanvasHelper } from '#tests/helpers/canvas'
|
|
|
|
async function stubGoogleFonts(page: Page) {
|
|
await page.addInitScript(() => {
|
|
const originalFetch = window.fetch.bind(window)
|
|
// The page's `fetch` has no Bun namespace properties, so the stub is asserted, not widened.
|
|
window.fetch = (async (input, init) => {
|
|
let url: string
|
|
if (typeof input === 'string') url = input
|
|
else if (input instanceof URL) url = input.href
|
|
else url = input.url
|
|
if (url.startsWith('https://www.googleapis.com/webfonts/v1/webfonts')) {
|
|
return new Response(JSON.stringify({ items: [] }), {
|
|
status: 200,
|
|
headers: { 'content-type': 'application/json' }
|
|
})
|
|
}
|
|
return originalFetch(input, init)
|
|
}) as typeof window.fetch
|
|
})
|
|
}
|
|
|
|
async function startEmptyTextEdit(page: Page) {
|
|
return await page.evaluate(() => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
|
|
const id = store.createShape('TEXT', 120, 120, 280, 36)
|
|
store.graph.updateNode(id, {
|
|
text: '',
|
|
fontSize: 32,
|
|
fontFamily: 'Inter',
|
|
textAutoResize: 'HEIGHT',
|
|
fills: [{ type: 'SOLID', color: { r: 0, g: 0, b: 0, a: 1 }, visible: true, opacity: 1 }]
|
|
})
|
|
store.select([id])
|
|
store.startTextEditing(id)
|
|
store.requestRender()
|
|
return id
|
|
})
|
|
}
|
|
|
|
test('Hangul text input commits without CanvasKit paragraph errors', async ({ page }) => {
|
|
const canvas = new CanvasHelper(page)
|
|
await stubGoogleFonts(page)
|
|
await page.goto('/?test&no-chrome&no-rulers')
|
|
await canvas.waitForInit()
|
|
|
|
const id = await startEmptyTextEdit(page)
|
|
|
|
await page.locator('textarea[aria-hidden="true"]').fill('환경설정')
|
|
await canvas.waitForRender()
|
|
await canvas.click(20, 20)
|
|
await canvas.waitForRender()
|
|
|
|
const result = await page.evaluate((nodeId) => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
const node = store.graph.getNode(nodeId)
|
|
if (!node || node.type !== 'TEXT') return null
|
|
return {
|
|
editingTextId: store.state.editingTextId,
|
|
height: node.height,
|
|
text: node.text
|
|
}
|
|
}, id)
|
|
|
|
expect(result).toMatchObject({
|
|
editingTextId: null,
|
|
text: '환경설정'
|
|
})
|
|
expect(result?.height).toBeGreaterThan(0)
|
|
canvas.assertNoErrors()
|
|
})
|
|
|
|
test('Hangul composition updates are visible before IME commit', async ({ page }) => {
|
|
const canvas = new CanvasHelper(page)
|
|
await stubGoogleFonts(page)
|
|
await page.goto('/?test&no-chrome&no-rulers')
|
|
await canvas.waitForInit()
|
|
|
|
const id = await startEmptyTextEdit(page)
|
|
|
|
const composing = await page.evaluate((nodeId) => {
|
|
const store = window.openPencil?.getStore?.()
|
|
const textarea = document.querySelector<HTMLTextAreaElement>('textarea[aria-hidden="true"]')
|
|
if (!store || !textarea) throw new Error('Text edit session was not initialized')
|
|
|
|
const readText = () => {
|
|
const node = store.graph.getNode(nodeId)
|
|
return node?.type === 'TEXT' ? node.text : null
|
|
}
|
|
const update = (text: string) => {
|
|
textarea.value = text
|
|
textarea.dispatchEvent(new CompositionEvent('compositionupdate', { data: text }))
|
|
textarea.dispatchEvent(
|
|
new InputEvent('input', {
|
|
data: text,
|
|
inputType: 'insertCompositionText',
|
|
isComposing: true
|
|
})
|
|
)
|
|
return readText()
|
|
}
|
|
|
|
textarea.dispatchEvent(new CompositionEvent('compositionstart'))
|
|
const steps = [update('ㅎ'), update('하'), update('한')]
|
|
|
|
textarea.dispatchEvent(new CompositionEvent('compositionend', { data: '한' }))
|
|
const afterEnd = readText()
|
|
|
|
textarea.value = '한'
|
|
textarea.dispatchEvent(new InputEvent('input', { data: '한', inputType: 'insertText' }))
|
|
const afterTrailingInput = readText()
|
|
|
|
return {
|
|
afterEnd,
|
|
afterTrailingInput,
|
|
editingTextId: store.state.editingTextId,
|
|
steps
|
|
}
|
|
}, id)
|
|
|
|
expect(composing).toEqual({
|
|
afterEnd: '한',
|
|
afterTrailingInput: '한',
|
|
editingTextId: id,
|
|
steps: ['ㅎ', '하', '한']
|
|
})
|
|
|
|
await canvas.click(20, 20)
|
|
const committed = await page.evaluate((nodeId) => {
|
|
const store = window.openPencil?.getStore?.()
|
|
if (!store) throw new Error('OpenPencil store not initialized')
|
|
return {
|
|
editingTextId: store.state.editingTextId,
|
|
text: store.graph.getNode(nodeId)?.text
|
|
}
|
|
}, id)
|
|
|
|
expect(committed).toEqual({
|
|
editingTextId: null,
|
|
text: '한'
|
|
})
|
|
canvas.assertNoErrors()
|
|
})
|