mirror of
https://github.com/nodejs/node.git
synced 2026-11-30 11:55:44 -05:00
Co-authored-by: Brian Muenzenmeyer <brian.muenzenmeyer@gmail.com> Signed-off-by: avivkeller <me@aviv.sh> PR-URL: https://github.com/nodejs/node/pull/66713 Reviewed-By: Claudio Wunder <cwunder@gnome.org> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
76 lines
2.9 KiB
JavaScript
76 lines
2.9 KiB
JavaScript
import * as common from '../common/index.mjs';
|
|
|
|
import assert from 'node:assert';
|
|
import fs from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
|
|
// This tests that `make doc` generates HTML and JSON.
|
|
// Note that for this test to pass, `make doc` must be run first.
|
|
|
|
if (common.isWindows) {
|
|
common.skip('`make doc` does not run on Windows');
|
|
}
|
|
|
|
// Not all files under `doc/api` are expected in the generated output.
|
|
// Parse out list of excluded files.
|
|
let excludes = [];
|
|
const makefile = await fs.open(new URL('../../Makefile', import.meta.url));
|
|
try {
|
|
// Find the `skip_apidoc_files = ` line and parse out the list of files.
|
|
for await (const line of makefile.readLines()) {
|
|
if (line.startsWith('skip_apidoc_files')) {
|
|
excludes = line.split('=')[1]?.trim().split(/\s/).map((n) => path.basename(n));
|
|
}
|
|
}
|
|
} finally {
|
|
makefile.close();
|
|
}
|
|
|
|
const outdir = new URL('../../out/doc/api/', import.meta.url);
|
|
const files = await fs.readdir(outdir);
|
|
|
|
// Explicitly check for `index.html`, `all.html` and `all.json` as there are no
|
|
// corresponding Markdown files in `doc/api`.
|
|
const expectedExtras = ['index.html', 'all.html', 'all.json'];
|
|
for (const name of expectedExtras) {
|
|
assert(files.includes(name), `${name} was not generated (checked ${files})`);
|
|
}
|
|
|
|
// Check that every markdown file in `doc/api` was processed.
|
|
const sources = [];
|
|
for await (const file of await fs.opendir(new URL('../../doc/api/', import.meta.url))) {
|
|
// Only expect markdown files in doc/api.
|
|
assert.strictEqual(path.extname(file.name), '.md');
|
|
sources.push(path.basename(file.name, '.md'));
|
|
|
|
// Always expect markdown file in out/doc/api.
|
|
assert(files.includes(file.name), `${file.name} not found (checked ${files})`);
|
|
|
|
const htmlFile = `${path.basename(file.name, '.md')}.html`;
|
|
const jsonFile = `${path.basename(file.name, '.md')}.json`;
|
|
// Excluded files should not generate HTML and json files.
|
|
if (excludes.includes(file.name)) {
|
|
assert(!files.includes(htmlFile), `${htmlFile} was unexpectedly generated (checked ${files})`);
|
|
assert(!files.includes(jsonFile), `${jsonFile} was unexpectedly generated (checked ${files})`);
|
|
} else {
|
|
for (const generated of [htmlFile, jsonFile]) {
|
|
assert(files.includes(generated), `${generated} was not generated (checked ${files})`);
|
|
const { size } = await fs.stat(new URL(generated, outdir));
|
|
assert.notStrictEqual(size, 0, `${generated} is empty`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Every generated page must come from a current Markdown file, so a stale
|
|
// `out/doc/api` (e.g. from a renamed document) is noticed.
|
|
const expectedPages = ['404.html', 'apilinks.json', ...expectedExtras];
|
|
for (const name of files) {
|
|
const extension = path.extname(name);
|
|
if (extension !== '.html' && extension !== '.json') continue;
|
|
if (expectedPages.includes(name)) continue;
|
|
assert(
|
|
sources.includes(path.basename(name, extension)),
|
|
`Unexpected output: out/doc/api/${name}, remove and rerun.`,
|
|
);
|
|
}
|