From d23baf625bd6df661858d611d1e9ba4479bb8524 Mon Sep 17 00:00:00 2001 From: "arrz.dev" <55147716+arrzdev@users.noreply.github.com> Date: Mon, 16 Nov 2026 03:26:08 +0000 Subject: [PATCH] test(website): the nine partial docs samples are completed and typechecked, and no block may be partial Route files are checked against a short list of route ids, a service worker module against the worker lib. The list, pull-to-refresh and not-found samples gain the lines they were missing. --- website/DOCS_AUTHORING.md | 9 ++-- .../src/content/docs/pages/hooks-updates.ts | 3 +- website/src/content/docs/pages/list.ts | 11 +++- .../src/content/docs/pages/pull-to-refresh.ts | 5 +- website/src/content/docs/pages/quick-start.ts | 1 - website/src/content/docs/pages/rendering.ts | 1 - website/src/content/docs/pages/routing.ts | 9 ++-- website/src/content/docs/pages/theming.ts | 1 - website/src/content/docs/samples.test.ts | 50 +++++++++++++++---- 9 files changed, 65 insertions(+), 25 deletions(-) diff --git a/website/DOCS_AUTHORING.md b/website/DOCS_AUTHORING.md index ecc1060d..04755d23 100644 --- a/website/DOCS_AUTHORING.md +++ b/website/DOCS_AUTHORING.md @@ -24,9 +24,12 @@ and the docs say what is true today. `src/content/docs/samples.test.ts` typechecks every `ts` and `tsx` code block and demo source against that package, so a renamed prop or a changed return fails the test. A sample with no import gets the adaptv names it uses; JSX or a `return` with no component around it - is wrapped in one; a name you never declare (`rows`, `Title`) is a placeholder. A block that - still cannot compile (a route file, a service worker, a snippet cut mid-tag) takes - `partial: true`. Fix the sample first; the test caps how many blocks may be partial. + is wrapped in one; a name you never declare (`rows`, `Title`) is a placeholder. A route file + is checked against the route ids listed in `samples.test.ts` (`ROUTE_IDS`): add the id your + sample uses. A module that imports `adaptv/sw` is checked against the worker lib, so it + declares `self` as `ServiceWorkerGlobalScope`. A block that still cannot compile (a snippet cut + mid-tag) takes `partial: true`. Fix the sample first; the test allows no partial block today, + so a new one means raising that cap with the reason in the PR. - JSDoc in the source is the best starting text. Rewrite it for a reader who has never seen the repo: drop decision-register ids (L20, O7, B9), internal file paths and history. - The engines underneath (the router, the native shell) can be named when it helps someone debug, diff --git a/website/src/content/docs/pages/hooks-updates.ts b/website/src/content/docs/pages/hooks-updates.ts index 05d2a01b..043abd15 100644 --- a/website/src/content/docs/pages/hooks-updates.ts +++ b/website/src/content/docs/pages/hooks-updates.ts @@ -133,9 +133,10 @@ export default defineApp({ type: "code", label: "src/sw/push.ts", lang: "ts", - partial: true, code: `import { onAppMessage, sendToApp } from "adaptv/sw" +declare const self: ServiceWorkerGlobalScope + self.addEventListener("push", (event) => { event.waitUntil(sendToApp({ type: "push", body: event.data?.text() })) }) diff --git a/website/src/content/docs/pages/list.ts b/website/src/content/docs/pages/list.ts index ecd2c859..320e92a2 100644 --- a/website/src/content/docs/pages/list.ts +++ b/website/src/content/docs/pages/list.ts @@ -134,8 +134,15 @@ const rows: Row[] = Array.from({ length: 10_000 }, (_, index) => ({ type: "code", label: "feed.tsx", lang: "tsx", - partial: true, - code: `const loadMore = useCallback(async () => { + code: `import { List } from "adaptv/components" +import { useCallback, useRef, useState } from "react" + +type Post = { id: string; title: string } + +const [posts, setPosts] = useState([]) +const loading = useRef(false) + +const loadMore = useCallback(async () => { if (loading.current) return loading.current = true const next = await fetchPosts({ after: posts.at(-1)?.id }) diff --git a/website/src/content/docs/pages/pull-to-refresh.ts b/website/src/content/docs/pages/pull-to-refresh.ts index cb212bb2..2293f1cc 100644 --- a/website/src/content/docs/pages/pull-to-refresh.ts +++ b/website/src/content/docs/pages/pull-to-refresh.ts @@ -104,12 +104,13 @@ const scrollRef = useRef(null) type: "code", label: "dark-indicator.tsx", lang: "tsx", - partial: true, code: ``, +> + {rows} +`, }, { type: "p", diff --git a/website/src/content/docs/pages/quick-start.ts b/website/src/content/docs/pages/quick-start.ts index fbd48d3a..9b475488 100644 --- a/website/src/content/docs/pages/quick-start.ts +++ b/website/src/content/docs/pages/quick-start.ts @@ -111,7 +111,6 @@ export default rootRoute([index("pages/home.page.tsx")])`, type: "code", label: "home.page.tsx", lang: "tsx", - partial: true, code: `import { ScrollView, View } from "adaptv/components" import { createFileRoute } from "adaptv/router" diff --git a/website/src/content/docs/pages/rendering.ts b/website/src/content/docs/pages/rendering.ts index e88a747a..ebb0e4aa 100644 --- a/website/src/content/docs/pages/rendering.ts +++ b/website/src/content/docs/pages/rendering.ts @@ -98,7 +98,6 @@ export const page: DocPage = { type: "code", label: "src/routing/pages/orders.page.tsx", lang: "tsx", - partial: true, code: `import { createFileRoute } from "adaptv/router" export const Route = createFileRoute("/orders")({ diff --git a/website/src/content/docs/pages/routing.ts b/website/src/content/docs/pages/routing.ts index 1cabd7ba..5c959ec1 100644 --- a/website/src/content/docs/pages/routing.ts +++ b/website/src/content/docs/pages/routing.ts @@ -36,7 +36,6 @@ export default rootRoute([ type: "code", label: "src/routing/pages/docs/doc.page.tsx", lang: "tsx", - partial: true, code: `import { createFileRoute, notFound } from "adaptv/router" export const Route = createFileRoute("/_providers/docs/$slug")({ @@ -80,7 +79,6 @@ function DocRoute() { type: "code", label: "src/routing/layouts/providers.layout.tsx", lang: "tsx", - partial: true, code: `import { createFileRoute, Outlet } from "adaptv/router" import AppProviders from "@/providers/app-providers" @@ -137,8 +135,11 @@ export const Nav = () => ( type: "code", label: "adaptv.config.ts", lang: "ts", - partial: true, - code: `notFoundScreen: () => import("@/components/not-found-screen"),`, + code: `import { defineApp } from "adaptv/config" + +export default defineApp({ + notFoundScreen: () => import("@/components/not-found-screen"), +})`, }, { type: "h2", text: "Eject the router or the client entry" }, { diff --git a/website/src/content/docs/pages/theming.ts b/website/src/content/docs/pages/theming.ts index 44fe11ab..87d6dbc2 100644 --- a/website/src/content/docs/pages/theming.ts +++ b/website/src/content/docs/pages/theming.ts @@ -143,7 +143,6 @@ function ThemeToggle() { type: "code", label: "src/routing/pages/settings.page.tsx", lang: "tsx", - partial: true, code: `export const Route = createFileRoute("/settings")({ chromeTint: "#1e0033", component: Settings, diff --git a/website/src/content/docs/samples.test.ts b/website/src/content/docs/samples.test.ts index 6ce3a4e7..d1f8bf8e 100644 --- a/website/src/content/docs/samples.test.ts +++ b/website/src/content/docs/samples.test.ts @@ -21,9 +21,10 @@ vi.mock("@/assets/captures/ios-list.png?adaptv-image", () => ({ default: {} })) //small: a sample with no import at all gets the adaptv imports it uses, statements and //JSX with no component around them are put in one, and a name the sample never declares //and adaptv does not export is a placeholder (`rows`, `Title`). A fragment that still -//cannot compile sets `partial: true` on its block and is skipped: a route file (the ids -//`createFileRoute` accepts come from the app's generated route tree, which a docs page -//does not have), a service worker (it needs the worker's types) or a snippet cut mid-tag. +//cannot compile sets `partial: true` on its block and is skipped, such as a snippet cut +//mid-tag. A route file is checked against a short list of route ids (`ROUTE_IDS`, the +//generated route tree a docs page does not have), and a module that imports `adaptv/sw` +//against the worker lib instead of the DOM one. //Needs `pnpm build` at the root first, like every website test. type Sample = { id: string; ext: "ts" | "tsx"; code: string } @@ -164,7 +165,15 @@ const options: ts.CompilerOptions = { const VIRTUAL_DIR = resolve(".docs-samples") const virtualPath = ({ id, ext }: Sample) => join(VIRTUAL_DIR, `${id}.${ext}`) -//What a real app has and a sample may lean on: the ambient `createFileRoute`. +//What a real app has and a sample may lean on: the ambient `createFileRoute`, and the +//route ids its generated route tree would hold (`createFileRoute` accepts only those). +const ROUTE_IDS = [ + "/", + "/orders", + "/settings", + "/_providers", + "/_providers/docs/$slug", +] const PRELUDE = join(VIRTUAL_DIR, "prelude.d.ts") const files = new Map([ [ @@ -175,6 +184,9 @@ declare module "adaptv/router" { interface Register { router: AdaptvRouter } + interface FileRoutesByPath { +${ROUTE_IDS.map((id) => ` "${id}": { id: "${id}"; path: "${id}"; fullPath: "${id}"; preLoaderRoute: any; parentRoute: any }`).join("\n")} + } } `, ], @@ -192,7 +204,24 @@ host.getSourceFile = (path, languageVersion, ...rest) => { : ts.createSourceFile(path, text, languageVersion, true) } -const program = ts.createProgram([...files.keys()], options, host) +//a service worker module runs where `self` is the worker scope: its own program, with +//the worker lib in place of the DOM one +const isWorker = (sample: Sample) => /from "adaptv\/sw"/.test(sample.code) +const workerOptions: ts.CompilerOptions = { + ...options, + lib: ["lib.es2022.d.ts", "lib.webworker.d.ts"], +} +const workerSamples = SAMPLES.filter(isWorker).map(virtualPath) +const program = ts.createProgram( + [...files.keys()].filter((path) => !workerSamples.includes(path)), + options, + host, +) +const workerProgram = ts.createProgram( + [PRELUDE, ...workerSamples], + workerOptions, + host, +) //Not mistakes in a fragment: a name it never declares (2304, 2552) when adaptv does not //export it, what that makes implicit any (7005, 7006, 7031), and the app's own modules. @@ -207,11 +236,12 @@ function isPlaceholder(diagnostic: ts.Diagnostic): boolean { /** What the compiler says about one sample, one line each, with its position. */ function problems(sample: Sample): string[] { - const file = program.getSourceFile(virtualPath(sample)) + const owner = isWorker(sample) ? workerProgram : program + const file = owner.getSourceFile(virtualPath(sample)) if (file === undefined) return ["the sample was not compiled"] return [ - ...program.getSyntacticDiagnostics(file), - ...program.getSemanticDiagnostics(file), + ...owner.getSyntacticDiagnostics(file), + ...owner.getSemanticDiagnostics(file), ] .filter((diagnostic) => !isPlaceholder(diagnostic)) .map((diagnostic) => { @@ -257,11 +287,11 @@ describe("samples", () => { }) //`partial` is for what cannot compile, not for what is inconvenient to fix - it("has few blocks marked partial", () => { + it("has no block marked partial", () => { const partial = ALL_DOCS.flatMap((page) => page.blocks).filter( (block) => "partial" in block && block.partial === true, ) - expect(partial.length).toBeLessThanOrEqual(12) + expect(partial.length).toBe(0) }) //a walker that stops finding blocks would pass every page below without checking anything