* 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
103 lines
3.4 KiB
TypeScript
103 lines
3.4 KiB
TypeScript
import { describe, expect, test } from 'bun:test'
|
|
import { readFile } from 'node:fs/promises'
|
|
|
|
import * as v from 'valibot'
|
|
|
|
import {
|
|
BASELINE_ECMASCRIPT_LIB,
|
|
BROWSER_BASELINE,
|
|
SUPPORT_SENTINELS,
|
|
browserslistQueries,
|
|
missingSupportSentinels,
|
|
viteBuildTarget,
|
|
type BaselineBrowser
|
|
} from '@/app/shell/support/baseline'
|
|
|
|
import { repoPath } from '#tests/helpers/paths'
|
|
|
|
const BROWSERS = Object.keys(BROWSER_BASELINE) as BaselineBrowser[]
|
|
|
|
const oxlintSettingsSchema = v.object({
|
|
settings: v.object({ browsers: v.array(v.string()) })
|
|
})
|
|
const tsconfigLibSchema = v.object({
|
|
compilerOptions: v.object({ lib: v.array(v.string()) })
|
|
})
|
|
const tsconfigTypesSchema = v.object({
|
|
compilerOptions: v.object({ types: v.array(v.string()) })
|
|
})
|
|
|
|
/** tsconfigs whose output ships to browsers and must stay on the baseline lib. */
|
|
const BROWSER_TSCONFIGS = [
|
|
'tsconfig.json',
|
|
'packages/core/tsconfig.json',
|
|
'packages/vue/tsconfig.json',
|
|
'packages/dom-css/tsconfig.json',
|
|
'packages/fig/tsconfig.json',
|
|
'packages/pen/tsconfig.json'
|
|
]
|
|
|
|
async function readJSON<T>(schema: v.GenericSchema<unknown, T>, path: string): Promise<T> {
|
|
return v.parse(schema, JSON.parse(await readFile(repoPath(path), 'utf8')))
|
|
}
|
|
|
|
describe('browser baseline', () => {
|
|
test('derives the Vite build target from the baseline', () => {
|
|
expect(viteBuildTarget()).toEqual([
|
|
'chrome111',
|
|
'edge111',
|
|
'firefox128',
|
|
'safari16.4',
|
|
'ios16.4'
|
|
])
|
|
})
|
|
|
|
test('oxlint checks Web APIs against the same browsers', async () => {
|
|
const { settings } = await readJSON(oxlintSettingsSchema, 'oxlint.json')
|
|
expect(settings.browsers).toEqual(browserslistQueries())
|
|
})
|
|
|
|
test.each(BROWSER_TSCONFIGS)('%s pins the baseline ECMAScript lib', async (path) => {
|
|
const { compilerOptions } = await readJSON(tsconfigLibSchema, path)
|
|
expect(compilerOptions.lib[0]).toBe(BASELINE_ECMASCRIPT_LIB)
|
|
})
|
|
|
|
/**
|
|
* The app program is what `src/**` is judged by, so its global types decide which platform the
|
|
* app is written against. Bun's disagree with the browser's — its `fetch` carries a `preconnect`
|
|
* the DOM one does not — and leaving `types` unpinned lets any root `@types` package change that.
|
|
*/
|
|
test('the app tsconfig pins global types and excludes Bun', async () => {
|
|
const { compilerOptions } = await readJSON(tsconfigTypesSchema, 'tsconfig.json')
|
|
expect(compilerOptions.types).not.toContain('bun')
|
|
})
|
|
|
|
test.each(BROWSERS)('no sentinel demands more than the %s baseline', (browser) => {
|
|
for (const sentinel of SUPPORT_SENTINELS) {
|
|
const since = sentinel.since[browser]
|
|
expect(since, `${sentinel.name} has no ${browser} entry`).toBeDefined()
|
|
expect(since ?? Number.POSITIVE_INFINITY).toBeLessThanOrEqual(BROWSER_BASELINE[browser])
|
|
}
|
|
})
|
|
|
|
test.each(BROWSERS)('at least one sentinel marks the %s baseline exactly', (browser) => {
|
|
const newest = Math.max(...SUPPORT_SENTINELS.map((sentinel) => sentinel.since[browser] ?? 0))
|
|
expect(newest).toBe(BROWSER_BASELINE[browser])
|
|
})
|
|
|
|
test('reports the names of failing sentinels and tolerates throwing tests', () => {
|
|
const missing = missingSupportSentinels([
|
|
{ name: 'present', since: {}, test: () => true },
|
|
{ name: 'absent', since: {}, test: () => false },
|
|
{
|
|
name: 'throws',
|
|
since: {},
|
|
test: () => {
|
|
throw new TypeError('not a function')
|
|
}
|
|
}
|
|
])
|
|
expect(missing).toEqual(['absent', 'throws'])
|
|
})
|
|
})
|