1
1
'use strict' ;
2
2
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
+
3
6
const common = require ( '../common' ) ;
4
7
5
8
const assert = require ( 'assert' ) ;
6
- const exec = require ( 'child_process' ) . exec ;
7
9
const fs = require ( 'fs' ) ;
8
10
const path = require ( 'path' ) ;
9
11
10
12
if ( common . isWindows ) {
11
13
common . skip ( 'Do not make doc on Windows' ) ;
12
14
}
13
15
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
+ }
31
32
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 ;
38
38
}
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` ) ;
47
39
}
48
- }
40
+ return true ;
41
+ } ) ;
49
42
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