mirror of
https://github.com/nodejs/node.git
synced 2024-11-30 07:27:22 +01:00
c57e11c2f6
PR-URL: https://github.com/nodejs/node/pull/21913 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
64 lines
2.0 KiB
JavaScript
64 lines
2.0 KiB
JavaScript
'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(__dirname, '..', '..', 'out', 'doc', 'api');
|
|
const mdPath = path.resolve(__dirname, '..', '..', 'doc', 'api');
|
|
const allMD = fs.readdirSync(mdPath);
|
|
const allDocs = fs.readdirSync(apiPath);
|
|
assert.ok(allDocs.includes('index.html'));
|
|
|
|
const actualDocs = allDocs.filter(
|
|
(name) => {
|
|
const extension = path.extname(name);
|
|
return extension === '.html' || extension === '.json';
|
|
}
|
|
);
|
|
|
|
for (const name of actualDocs) {
|
|
if (name.startsWith('all.')) continue;
|
|
|
|
assert.ok(
|
|
allMD.includes(name.replace(/\.\w+$/, '.md')),
|
|
`Unexpected output: out/doc/api/${name}, remove and rerun.`
|
|
);
|
|
}
|
|
|
|
const toc = fs.readFileSync(path.resolve(apiPath, 'index.html'), 'utf8');
|
|
const re = /href="([^/]+\.html)"/;
|
|
const globalRe = new RegExp(re, 'g');
|
|
const links = toc.match(globalRe);
|
|
assert.notStrictEqual(links, null);
|
|
|
|
// Filter out duplicate links, leave just filenames, add expected JSON files.
|
|
const linkedHtmls = [...new Set(links)].map((link) => link.match(re)[1]);
|
|
const expectedJsons = linkedHtmls
|
|
.map((name) => name.replace('.html', '.json'));
|
|
const expectedDocs = linkedHtmls.concat(expectedJsons);
|
|
|
|
// Test that all the relative links in the TOC match to the actual documents.
|
|
for (const expectedDoc of expectedDocs) {
|
|
assert.ok(actualDocs.includes(expectedDoc), `${expectedDoc} does not exist`);
|
|
}
|
|
|
|
// Test that all the actual documents match to the relative links in the TOC
|
|
// and that they are not empty files.
|
|
for (const actualDoc of actualDocs) {
|
|
assert.ok(
|
|
expectedDocs.includes(actualDoc), `${actualDoc} does not match TOC`);
|
|
|
|
assert.ok(
|
|
fs.statSync(path.join(apiPath, actualDoc)).size !== 0,
|
|
`${actualDoc} is empty`
|
|
);
|
|
}
|