|
| 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