11import assert from 'node:assert/strict' ;
22import { describe , it } from 'node:test' ;
33
4- import { buildIndexPage , buildStabilityOverview } from '../index.mjs' ;
4+ import {
5+ buildStabilityOverview ,
6+ injectDocumentationIndex ,
7+ } from '../documentationIndex.mjs' ;
58
69const fakeHead = ( api , name , stabilityIndex , depth = 1 ) => ( {
710 api,
@@ -20,32 +23,59 @@ const fakeHead = (api, name, stabilityIndex, depth = 1) => ({
2023const findChild = ( node , tagName ) =>
2124 node . children . find ( child => child . tagName === tagName ) ;
2225
23- describe ( 'buildIndexPage' , ( ) => {
24- it ( 'returns a synthetic `index` head with an "Index" heading' , ( ) => {
25- const { head } = buildIndexPage ( [ ] ) ;
26+ describe ( 'injectDocumentationIndex' , ( ) => {
27+ const createEntry = tags => ( {
28+ ...fakeHead ( 'index' , 'Index' , null ) ,
29+ tags,
30+ content : { type : 'root' , children : [ ] } ,
31+ } ) ;
32+
33+ it ( 'appends the overview to entries tagged DOCUMENTATION_INDEX' , ( ) => {
34+ const tagged = createEntry ( [ 'DOCUMENTATION_INDEX' ] ) ;
35+ const untagged = createEntry ( undefined ) ;
36+
37+ injectDocumentationIndex (
38+ [ tagged , untagged ] ,
39+ [ fakeHead ( 'fs' , 'fs' , 2 ) , fakeHead ( 'assert' , 'assert' , 2 ) ]
40+ ) ;
2641
27- assert . equal ( head . api , 'index' ) ;
28- assert . equal ( head . path , '/index' ) ;
29- assert . equal ( head . basename , 'index' ) ;
30- assert . equal ( head . heading . data . name , 'Index' ) ;
31- assert . equal ( head . synthetic , true ) ;
42+ const table = findChild ( tagged . content , 'table' ) ;
43+ assert . equal ( findChild ( table , 'tbody' ) . children . length , 2 ) ;
44+ assert . equal ( untagged . content . children . length , 0 ) ;
3245 } ) ;
3346
3447 it ( 'sorts the stability overview rows alphabetically by API name' , ( ) => {
35- const { entries } = buildIndexPage ( [
36- fakeHead ( 'fs' , 'fs' , 2 ) ,
37- fakeHead ( 'assert' , 'assert' , 2 ) ,
38- fakeHead ( 'crypto' , 'crypto' , 2 ) ,
39- ] ) ;
48+ const entry = createEntry ( [ 'DOCUMENTATION_INDEX' ] ) ;
49+
50+ injectDocumentationIndex (
51+ [ entry ] ,
52+ [
53+ fakeHead ( 'fs' , 'fs' , 2 ) ,
54+ fakeHead ( 'assert' , 'assert' , 2 ) ,
55+ fakeHead ( 'crypto' , 'crypto' , 2 ) ,
56+ ]
57+ ) ;
4058
41- const table = findChild ( entries [ 0 ] . content , 'table' ) ;
59+ const table = findChild ( entry . content , 'table' ) ;
4260 const rows = findChild ( table , 'tbody' ) . children ;
4361 const names = rows . map (
4462 row => row . children [ 0 ] . children [ 0 ] . children [ 0 ] . value
4563 ) ;
4664
4765 assert . deepEqual ( names , [ 'assert' , 'crypto' , 'fs' ] ) ;
4866 } ) ;
67+
68+ it ( 'excludes module heads without a stability index' , ( ) => {
69+ const entry = createEntry ( [ 'DOCUMENTATION_INDEX' ] ) ;
70+
71+ injectDocumentationIndex (
72+ [ entry ] ,
73+ [ fakeHead ( 'fs' , 'fs' , 2 ) , fakeHead ( 'synopsis' , 'Usage' , null ) ]
74+ ) ;
75+
76+ const table = findChild ( entry . content , 'table' ) ;
77+ assert . equal ( findChild ( table , 'tbody' ) . children . length , 1 ) ;
78+ } ) ;
4979} ) ;
5080
5181describe ( 'buildStabilityOverview' , ( ) => {
0 commit comments