test: test make doc and verify toc

PR-URL: https://github.com/nodejs/node/pull/16208
Fixes: https://github.com/nodejs/build/issues/887
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Joyee Cheung committed 2017-10-18 20:24:22 +08:00
1 parent a5262f1a3b
commit df5dc2da39
2 files changed
+46 -2

No files matched your search

+3 -2
View File
@@ -200,6 +200,7 @@ else
test: all
$(MAKE) build-addons
$(MAKE) build-addons-napi
$(MAKE) doc
$(MAKE) cctest
$(PYTHON) tools/test.py --mode=release -J \
$(CI_ASYNC_HOOKS) \
@@ -379,7 +380,7 @@ test-ci-js: | clear-stalled
fi
test-ci: LOGLEVEL := info
test-ci: | clear-stalled build-addons build-addons-napi
test-ci: | clear-stalled build-addons build-addons-napi doc
out/Release/cctest --gtest_output=tap:cctest.tap
$(PYTHON) tools/test.py $(PARALLEL_ARGS) -p tap --logfile test.tap \
--mode=release --flaky-tests=$(FLAKY_TESTS) \
@@ -515,7 +516,7 @@ doc: $(NODE_EXE) doc-only
$(apidoc_dirs):
mkdir -p $@
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets/
out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets
cp $< $@
out/doc/%: doc/%
+43
View File
@@ -0,0 +1,43 @@
'use strict';
const common = require('../common');
if (common.isWindows) {
common.skip('`make doc` does not run on Windows');
}
// This tests that `make doc` generates the documentation properly.
// Note that for this test to pass, `make doc` must be run first.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const apiPath = path.resolve(common.projectDir, 'out', 'doc', 'api');
const docs = fs.readdirSync(apiPath);
assert.ok(docs.includes('_toc.html'));
const toc = fs.readFileSync(path.resolve(apiPath, '_toc.html'), 'utf8');
const re = /href="([^/]+\.html)"/;
const globalRe = new RegExp(re, 'g');
const links = toc.match(globalRe);
assert.notStrictEqual(links, null);
// Test that all the relative links in the TOC of the documentation
// work and all the generated documents are linked in TOC.
const linkedHtmls = links.map((link) => link.match(re)[1]);
for (const html of linkedHtmls) {
assert.ok(docs.includes(html), `${html} does not exist`);
}
const excludes = ['.json', '_toc', 'assets'];
const generatedHtmls = docs.filter(function(doc) {
for (const exclude of excludes) {
if (doc.includes(exclude)) {
return false;
}
}
return true;
});
for (const html of generatedHtmls) {
assert.ok(linkedHtmls.includes(html), `${html} is not linked in toc`);
}