* 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
117 lines
3.6 KiB
TypeScript
117 lines
3.6 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
|
|
import { DEFAULT_WEB_FONT_PROVIDER_SETTINGS } from '@open-pencil/core/text'
|
|
|
|
import { useFontSettings, type FontSettingsActions } from '@/components/font-settings/use'
|
|
|
|
function actions(overrides: Partial<FontSettingsActions> = {}): FontSettingsActions {
|
|
let accessState: ReturnType<FontSettingsActions['localFontAccessState']> = 'prompt'
|
|
return {
|
|
async clearDownloadedFontCache() {
|
|
return undefined
|
|
},
|
|
async downloadedFontCacheSummary() {
|
|
return { count: 2, byteLength: 1_572_864, updatedAt: 1_700_000_000_000 }
|
|
},
|
|
localFontAccessState() {
|
|
return accessState
|
|
},
|
|
async predownloadFallbackFonts() {
|
|
return undefined
|
|
},
|
|
async requestLocalFontAccess() {
|
|
accessState = 'granted'
|
|
return ['Inter']
|
|
},
|
|
onlineFontsEnabled: { value: true },
|
|
fontProviderSettings: { value: { ...DEFAULT_WEB_FONT_PROVIDER_SETTINGS } },
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
describe('useFontSettings', () => {
|
|
test('loads cache summary and formats labels', async () => {
|
|
const settings = useFontSettings(actions())
|
|
|
|
await settings.refreshSummary()
|
|
|
|
expect(settings.cacheCount.value).toBe(2)
|
|
expect(settings.accessStateLabel.value).toBe('Not requested')
|
|
expect(settings.canRequestLocalFonts.value).toBe(true)
|
|
expect(settings.cacheSize.value).toBe('1.5 MB')
|
|
expect(settings.cacheUpdatedLabel.value).not.toBe('Never')
|
|
expect(settings.busyAction.value).toBeNull()
|
|
})
|
|
|
|
test('requests local font access and updates status', async () => {
|
|
const settings = useFontSettings(actions())
|
|
|
|
await settings.requestAccess()
|
|
|
|
expect(settings.accessState.value).toBe('granted')
|
|
expect(settings.accessStateLabel.value).toBe('Enabled')
|
|
expect(settings.canRequestLocalFonts.value).toBe(false)
|
|
expect(settings.status.value).toBe('Local font access enabled.')
|
|
expect(settings.busyAction.value).toBeNull()
|
|
})
|
|
|
|
test('downloads fallbacks then refreshes cache summary', async () => {
|
|
const calls: string[] = []
|
|
const settings = useFontSettings(
|
|
actions({
|
|
async predownloadFallbackFonts() {
|
|
calls.push('download')
|
|
},
|
|
async downloadedFontCacheSummary() {
|
|
calls.push('summary')
|
|
return { count: 3, byteLength: 3_145_728, updatedAt: null }
|
|
}
|
|
})
|
|
)
|
|
|
|
await settings.downloadFallbacks()
|
|
|
|
expect(calls).toEqual(['download', 'summary'])
|
|
expect(settings.cacheCount.value).toBe(3)
|
|
expect(settings.cacheSize.value).toBe('3.0 MB')
|
|
expect(settings.status.value).toBe('Fallback fonts downloaded.')
|
|
})
|
|
|
|
test('clears cache then refreshes cache summary', async () => {
|
|
const calls: string[] = []
|
|
const settings = useFontSettings(
|
|
actions({
|
|
async clearDownloadedFontCache() {
|
|
calls.push('clear')
|
|
},
|
|
async downloadedFontCacheSummary() {
|
|
calls.push('summary')
|
|
return { count: 0, byteLength: 0, updatedAt: null }
|
|
}
|
|
})
|
|
)
|
|
|
|
await settings.clearCache()
|
|
|
|
expect(calls).toEqual(['clear', 'summary'])
|
|
expect(settings.cacheCount.value).toBe(0)
|
|
expect(settings.cacheSize.value).toBe('0 MB')
|
|
expect(settings.status.value).toBe('Downloaded font cache cleared.')
|
|
})
|
|
|
|
test('reports action failures without leaving busy state stuck', async () => {
|
|
const settings = useFontSettings(
|
|
actions({
|
|
async requestLocalFontAccess() {
|
|
throw new Error('denied')
|
|
}
|
|
})
|
|
)
|
|
|
|
await settings.requestAccess()
|
|
|
|
expect(settings.status.value).toBe('Local font access was not granted.')
|
|
expect(settings.busyAction.value).toBeNull()
|
|
})
|
|
})
|