@@ -5,14 +5,7 @@ import path from "node:path";
55import { DatabaseSync } from "node:sqlite" ;
66import 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
1710const require = createRequire ( import . meta. url ) ;
1811const REPO_ROOT = path . resolve (
@@ -21,7 +14,7 @@ const REPO_ROOT = path.resolve(
2114const TEMPLATES_DIR = path . join ( REPO_ROOT , "sqlpage" , "templates" ) ;
2215const 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> {
268262const templates = read_templates ( ) ;
269263const 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
0 commit comments