Skip to content

Commit df5dc2d

Browse files
committed
test: test make doc and verify toc
PR-URL: #16208 Fixes: nodejs/build#887 Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent a5262f1 commit df5dc2d

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

Makefile

+3-2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ else
200200
test: all
201201
$(MAKE) build-addons
202202
$(MAKE) build-addons-napi
203+
$(MAKE) doc
203204
$(MAKE) cctest
204205
$(PYTHON) tools/test.py --mode=release -J \
205206
$(CI_ASYNC_HOOKS) \
@@ -379,7 +380,7 @@ test-ci-js: | clear-stalled
379380
fi
380381

381382
test-ci: LOGLEVEL := info
382-
test-ci: | clear-stalled build-addons build-addons-napi
383+
test-ci: | clear-stalled build-addons build-addons-napi doc
383384
out/Release/cctest --gtest_output=tap:cctest.tap
384385
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
385386
--mode=release --flaky-tests=$(FLAKY_TESTS) \
@@ -515,7 +516,7 @@ doc: $(NODE_EXE) doc-only
515516
$(apidoc_dirs):
516517
mkdir -p $@
517518

518-
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
519+
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets
519520
cp $< $@
520521

521522
out/doc/%: doc/%

test/sequential/test-make-doc.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
const common = require('../common');
3+
if (common.isWindows) {
4+
common.skip('`make doc` does not run on Windows');
5+
}
6+
7+
// This tests that `make doc` generates the documentation properly.
8+
// Note that for this test to pass, `make doc` must be run first.
9+
10+
const assert = require('assert');
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
const apiPath = path.resolve(common.projectDir, 'out', 'doc', 'api');
15+
const docs = fs.readdirSync(apiPath);
16+
assert.ok(docs.includes('_toc.html'));
17+
18+
const toc = fs.readFileSync(path.resolve(apiPath, '_toc.html'), 'utf8');
19+
const re = /href="([^/]+\.html)"/;
20+
const globalRe = new RegExp(re, 'g');
21+
const links = toc.match(globalRe);
22+
assert.notStrictEqual(links, null);
23+
24+
// Test that all the relative links in the TOC of the documentation
25+
// work and all the generated documents are linked in TOC.
26+
const linkedHtmls = links.map((link) => link.match(re)[1]);
27+
for (const html of linkedHtmls) {
28+
assert.ok(docs.includes(html), `${html} does not exist`);
29+
}
30+
31+
const excludes = ['.json', '_toc', 'assets'];
32+
const generatedHtmls = docs.filter(function(doc) {
33+
for (const exclude of excludes) {
34+
if (doc.includes(exclude)) {
35+
return false;
36+
}
37+
}
38+
return true;
39+
});
40+
41+
for (const html of generatedHtmls) {
42+
assert.ok(linkedHtmls.includes(html), `${html} is not linked in toc`);
43+
}

0 commit comments

Comments
 (0)