11'use strict' ;
22
3+ // This tests that `make doc` generates the documentation properly.
4+ // Note that for this test to pass, `make doc` must be run first.
5+
36const common = require ( '../common' ) ;
47
58const assert = require ( 'assert' ) ;
6- const exec = require ( 'child_process' ) . exec ;
79const fs = require ( 'fs' ) ;
810const path = require ( 'path' ) ;
911
1012if ( common . isWindows ) {
1113 common . skip ( 'Do not make doc on Windows' ) ;
1214}
1315
14- // Make sure all the relative links work and
15- // all the generated documents are linked in TOC
16- function verifyToc ( ) {
17- const apiPath = path . join ( common . projectDir , 'out' , 'doc' , 'api' ) ;
18- const docs = fs . readdirSync ( apiPath ) ;
19- assert . notStrictEqual ( docs . indexOf ( '_toc.html' ) , - 1 ) ;
20-
21- const toc = fs . readFileSync ( path . join ( apiPath , '_toc.html' ) , 'utf8' ) ;
22- const re = / h r e f = " ( [ ^ / ] + \. h t m l ) " / ;
23- const globalRe = new RegExp ( re , 'g' ) ;
24- const links = toc . match ( globalRe ) ;
25- assert . notStrictEqual ( links , null ) ;
26-
27- const linkedHtmls = links . map ( ( link ) => link . match ( re ) [ 1 ] ) ;
28- for ( const html of linkedHtmls ) {
29- assert . notStrictEqual ( docs . indexOf ( html ) , - 1 , `${ html } does not exist` ) ;
30- }
16+ const apiPath = path . join ( common . projectDir , 'out' , 'doc' , 'api' ) ;
17+ const docs = fs . readdirSync ( apiPath ) ;
18+ assert . ok ( docs . includes ( '_toc.html' ) ) ;
19+
20+ const toc = fs . readFileSync ( path . join ( apiPath , '_toc.html' ) , 'utf8' ) ;
21+ const re = / h r e f = " ( [ ^ / ] + \. h t m l ) " / ;
22+ const globalRe = new RegExp ( re , 'g' ) ;
23+ const links = toc . match ( globalRe ) ;
24+ assert . notStrictEqual ( links , null ) ;
25+
26+ // Test that all the relative links in the TOC of the documentation
27+ // work and all the generated documents are linked in TOC.
28+ const linkedHtmls = links . map ( ( link ) => link . match ( re ) [ 1 ] ) ;
29+ for ( const html of linkedHtmls ) {
30+ assert . ok ( docs . includes ( html ) , `${ html } does not exist` ) ;
31+ }
3132
32- const excludes = [ '.json' , '_toc' , 'assets' ] ;
33- const generatedHtmls = docs . filter ( function ( doc ) {
34- for ( const exclude of excludes ) {
35- if ( doc . includes ( exclude ) ) {
36- return false ;
37- }
33+ const excludes = [ '.json' , '_toc' , 'assets' ] ;
34+ const generatedHtmls = docs . filter ( function ( doc ) {
35+ for ( const exclude of excludes ) {
36+ if ( doc . includes ( exclude ) ) {
37+ return false ;
3838 }
39- return true ;
40- } ) ;
41-
42- for ( const html of generatedHtmls ) {
43- assert . notStrictEqual (
44- linkedHtmls . indexOf ( html ) ,
45- - 1 ,
46- `${ html } is not linked in toc` ) ;
4739 }
48- }
40+ return true ;
41+ } ) ;
4942
50- exec ( 'make doc' , {
51- cwd : common . projectDir
52- } , common . mustCall ( function onExit ( err , stdout , stderr ) {
53- console . log ( stdout ) ;
54- if ( stderr . length > 0 ) {
55- console . log ( 'stderr is not empty: ' ) ;
56- console . log ( stderr ) ;
57- }
58- assert . ifError ( err ) ;
59- verifyToc ( ) ;
60- } ) ) ;
43+ for ( const html of generatedHtmls ) {
44+ assert . ok ( linkedHtmls . includes ( html ) , `${ html } is not linked in toc` ) ;
45+ }
46+
0 commit comments