Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Commit 1593b3b

Browse files
joyeecheungaddaleax
authored andcommitted
test: test make doc and verify toc
PR-URL: nodejs/node#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 fbd7c6e commit 1593b3b

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ else
203203
test: all
204204
$(MAKE) build-addons
205205
$(MAKE) build-addons-napi
206+
$(MAKE) doc
206207
$(MAKE) cctest
207208
$(PYTHON) tools/test.py --mode=release -J \
208209
$(CI_ASYNC_HOOKS) \
@@ -382,7 +383,7 @@ test-ci-js: | clear-stalled
382383
fi
383384

384385
test-ci: LOGLEVEL := silent
385-
test-ci: | clear-stalled build-addons build-addons-napi
386+
test-ci: | clear-stalled build-addons build-addons-napi doc
386387
out/Release/cctest --gtest_output=tap:cctest.tap
387388
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p oneline \
388389
--mode=release --flaky-tests=$(FLAKY_TESTS) \
@@ -518,7 +519,7 @@ doc: $(NODE_EXE) doc-only
518519
$(apidoc_dirs):
519520
mkdir -p $@
520521

521-
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
522+
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets
522523
cp $< $@
523524

524525
out/doc/%: doc/%

test/sequential/test-make-doc.js

Lines changed: 43 additions & 0 deletions
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)