Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ built executable. Component suites use `fixtures/<suite>/{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.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -248,17 +241,18 @@ function read_documentation(): Map<string, TemplateProperties> {
}

const documented = new Map<string, TemplateProperties>();
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();
Expand All @@ -268,17 +262,10 @@ function read_documentation(): Map<string, TemplateProperties> {
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(),
);
});

Expand Down
2 changes: 1 addition & 1 deletion tests/js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"moduleResolution": "nodenext",
"types": ["node"]
},
"include": ["*.spec.ts"]
"include": ["*.spec.ts", "*.checks.ts"]
}
Loading