diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 808d8bab7..01cb8b5f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,8 @@ jobs: - run: cargo clippy --all-targets --all-features -- -D warnings - name: Prepare official website run: npm run site:build + - name: Check prepared component documentation + run: npm run site:test - name: Upload prepared website uses: actions/upload-artifact@v7 with: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 128ef1568..e35d71346 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,6 +67,10 @@ built executable. Component suites use `fixtures//{index.sql,test.ts}` an import the shared `fixture.ts` harness; root-level `*.spec.ts` files cover the official site. +For changes to component documentation, run `npm run site:test` after preparing +the site with `npm run site:build`. This checks the same reference the site serves +against the public components and their template properties. + Run `npx playwright test --grep @accessibility` from `tests/end-to-end` to audit the official site's component documentation and its live examples in SQLPage's stock light and dark themes with axe-core. The normal Playwright suite also runs it. diff --git a/package.json b/package.json index b338b5f7a..b2702c275 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "format": "biome format --write .", "fix": "biome check --fix --unsafe .", "site:build": "node scripts/site-build.mjs", + "site:test": "node --test tests/js/component_documentation.checks.ts", "site": "npm run build && npm run site:build && cd target/official-site && cargo run --locked --manifest-path ../../Cargo.toml" }, "repository": { diff --git a/tests/js/component_documentation.spec.ts b/tests/js/component_documentation.checks.ts similarity index 88% rename from tests/js/component_documentation.spec.ts rename to tests/js/component_documentation.checks.ts index c78a46838..71e95374a 100644 --- a/tests/js/component_documentation.spec.ts +++ b/tests/js/component_documentation.checks.ts @@ -5,14 +5,7 @@ import path from "node:path"; import { DatabaseSync } from "node:sqlite"; import test from "node:test"; -// Every built-in component is a Handlebars template in sqlpage/templates/, and -// its properties are documented as rows of the `parameter` table of the -// official site, built by the SQL migrations in examples/official-site/. -// Nothing links the two, so they drift: properties get added to a template and -// never documented, and documented properties outlive the code that read them. -// -// This test builds the official site's documentation database, reads the -// property names out of the templates, and asserts that the two agree. +// Check the documentation that the prepared site will actually serve. const require = createRequire(import.meta.url); const REPO_ROOT = path.resolve( @@ -21,7 +14,7 @@ const REPO_ROOT = path.resolve( const TEMPLATES_DIR = path.join(REPO_ROOT, "sqlpage", "templates"); const MIGRATIONS_DIR = path.join( REPO_ROOT, - "examples", + "target", "official-site", "sqlpage", "migrations", @@ -248,17 +241,18 @@ function read_documentation(): Map { } const documented = new Map(); + for (const { name } of db.prepare("select name from component").all()) { + assert.ok(typeof name === "string"); + documented.set(name, { top: new Set(), row: new Set() }); + } const rows = db .prepare("select component, name, top_level from parameter") .all(); for (const { component, name, top_level } of rows) { assert.ok(typeof component === "string" && typeof name === "string"); assert.equal(typeof top_level, "number"); - let entry = documented.get(component); - if (!entry) { - entry = { top: new Set(), row: new Set() }; - documented.set(component, entry); - } + const entry = documented.get(component); + assert.ok(entry, `No reference for ${component}`); (top_level ? entry.top : entry.row).add(name); } db.close(); @@ -268,17 +262,10 @@ function read_documentation(): Map { const templates = read_templates(); const documented = read_documentation(); -test("every component documented by the official site has a template", () => { - const missing = [...documented.keys()].filter( - (component) => - !templates.has(component) && - !COMPONENTS_WITHOUT_A_TEMPLATE.has(component), - ); +test("the official site documents every public component", () => { assert.deepEqual( - missing, - [], - `These components are documented but have no sqlpage/templates/*.handlebars file. ` + - `If they are rendered by src/render.rs, add them to COMPONENTS_WITHOUT_A_TEMPLATE.`, + [...documented.keys()].sort(), + [...templates.keys(), ...COMPONENTS_WITHOUT_A_TEMPLATE].sort(), ); }); diff --git a/tests/js/tsconfig.json b/tests/js/tsconfig.json index 752910d94..922c8ceaa 100644 --- a/tests/js/tsconfig.json +++ b/tests/js/tsconfig.json @@ -6,5 +6,5 @@ "moduleResolution": "nodenext", "types": ["node"] }, - "include": ["*.spec.ts"] + "include": ["*.spec.ts", "*.checks.ts"] }