Skip to content

Commit 4a61e42

Browse files
authored
Check the component reference in the prepared website (#1648)
1 parent b5640f9 commit 4a61e42

5 files changed

Lines changed: 19 additions & 25 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ jobs:
6666
- run: cargo clippy --all-targets --all-features -- -D warnings
6767
- name: Prepare official website
6868
run: npm run site:build
69+
- name: Check prepared component documentation
70+
run: npm run site:test
6971
- name: Upload prepared website
7072
uses: actions/upload-artifact@v7
7173
with:

‎CONTRIBUTING.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ built executable. Component suites use `fixtures/<suite>/{index.sql,test.ts}` an
6767
import the shared `fixture.ts` harness; root-level `*.spec.ts` files cover the
6868
official site.
6969

70+
For changes to component documentation, run `npm run site:test` after preparing
71+
the site with `npm run site:build`. This checks the same reference the site serves
72+
against the public components and their template properties.
73+
7074
Run `npx playwright test --grep @accessibility` from `tests/end-to-end` to audit
7175
the official site's component documentation and its live examples in SQLPage's
7276
stock light and dark themes with axe-core. The normal Playwright suite also runs it.

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"format": "biome format --write .",
1010
"fix": "biome check --fix --unsafe .",
1111
"site:build": "node scripts/site-build.mjs",
12+
"site:test": "node --test tests/js/component_documentation.checks.ts",
1213
"site": "npm run build && npm run site:build && cd target/official-site && cargo run --locked --manifest-path ../../Cargo.toml"
1314
},
1415
"repository": {

tests/js/component_documentation.spec.ts renamed to tests/js/component_documentation.checks.ts

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,7 @@ import path from "node:path";
55
import { DatabaseSync } from "node:sqlite";
66
import test from "node:test";
77

8-
// Every built-in component is a Handlebars template in sqlpage/templates/, and
9-
// its properties are documented as rows of the `parameter` table of the
10-
// official site, built by the SQL migrations in examples/official-site/.
11-
// Nothing links the two, so they drift: properties get added to a template and
12-
// never documented, and documented properties outlive the code that read them.
13-
//
14-
// This test builds the official site's documentation database, reads the
15-
// property names out of the templates, and asserts that the two agree.
8+
// Check the documentation that the prepared site will actually serve.
169

1710
const require = createRequire(import.meta.url);
1811
const REPO_ROOT = path.resolve(
@@ -21,7 +14,7 @@ const REPO_ROOT = path.resolve(
2114
const TEMPLATES_DIR = path.join(REPO_ROOT, "sqlpage", "templates");
2215
const MIGRATIONS_DIR = path.join(
2316
REPO_ROOT,
24-
"examples",
17+
"target",
2518
"official-site",
2619
"sqlpage",
2720
"migrations",
@@ -248,17 +241,18 @@ function read_documentation(): Map<string, TemplateProperties> {
248241
}
249242

250243
const documented = new Map<string, TemplateProperties>();
244+
for (const { name } of db.prepare("select name from component").all()) {
245+
assert.ok(typeof name === "string");
246+
documented.set(name, { top: new Set(), row: new Set() });
247+
}
251248
const rows = db
252249
.prepare("select component, name, top_level from parameter")
253250
.all();
254251
for (const { component, name, top_level } of rows) {
255252
assert.ok(typeof component === "string" && typeof name === "string");
256253
assert.equal(typeof top_level, "number");
257-
let entry = documented.get(component);
258-
if (!entry) {
259-
entry = { top: new Set(), row: new Set() };
260-
documented.set(component, entry);
261-
}
254+
const entry = documented.get(component);
255+
assert.ok(entry, `No reference for ${component}`);
262256
(top_level ? entry.top : entry.row).add(name);
263257
}
264258
db.close();
@@ -268,17 +262,10 @@ function read_documentation(): Map<string, TemplateProperties> {
268262
const templates = read_templates();
269263
const documented = read_documentation();
270264

271-
test("every component documented by the official site has a template", () => {
272-
const missing = [...documented.keys()].filter(
273-
(component) =>
274-
!templates.has(component) &&
275-
!COMPONENTS_WITHOUT_A_TEMPLATE.has(component),
276-
);
265+
test("the official site documents every public component", () => {
277266
assert.deepEqual(
278-
missing,
279-
[],
280-
`These components are documented but have no sqlpage/templates/*.handlebars file. ` +
281-
`If they are rendered by src/render.rs, add them to COMPONENTS_WITHOUT_A_TEMPLATE.`,
267+
[...documented.keys()].sort(),
268+
[...templates.keys(), ...COMPONENTS_WITHOUT_A_TEMPLATE].sort(),
282269
);
283270
});
284271

‎tests/js/tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
"moduleResolution": "nodenext",
77
"types": ["node"]
88
},
9-
"include": ["*.spec.ts"]
9+
"include": ["*.spec.ts", "*.checks.ts"]
1010
}

0 commit comments

Comments
 (0)