OXYGENHUB
◆ main oxygen-vscode / test / docs.test.mjs
1.4 KiB · last changed README as walkthroughs by task with a settings table, dated changelog entries, and a test that the docs keep up with the manifest 1 month ago source blame history raw
1
// The documentation keeps up with the manifest: every setting is described
2
// in the README, and the CHANGELOG has a dated entry for this version.
3
4
import { test } from "node:test";
5
import assert from "node:assert/strict";
6
import { readFileSync } from "node:fs";
7
8
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
9
const readme = readFileSync(new URL("../README.md", import.meta.url), "utf8");
10
const changelog = readFileSync(new URL("../CHANGELOG.md", import.meta.url), "utf8");
11
12
test("every setting is documented in the README's Settings table", () => {
13
  const cfg = pkg.contributes.configuration;
14
  const props = (Array.isArray(cfg) ? cfg : [cfg]).flatMap((c) => Object.keys(c.properties ?? {}));
15
  assert.ok(props.length > 0);
16
  const table = readme.slice(readme.indexOf("## Settings"));
17
  const missing = props.filter((p) => !table.includes("| `" + p + "` |"));
18
  assert.deepEqual(missing, [], "settings missing from the README");
19
});
20
21
test("the CHANGELOG's newest entry is this version, and every entry is dated", () => {
22
  const headings = [...changelog.matchAll(/^## (.+)$/gm)].map((m) => m[1]);
23
  assert.match(headings[0], new RegExp("^" + pkg.version.replace(/\./g, "\\.") + " \\(\\d{4}-\\d{2}-\\d{2}\\)$"));
24
  const undated = headings.filter((h) => !/^\d+\.\d+\.\d+ \(\d{4}-\d{2}-\d{2}\)$/.test(h));
25
  assert.deepEqual(undated, [], "entries without a version and date");
26
});