Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions tests/docs-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@ const docsRoot = join(repoRoot, 'docs');

// Directories sidebars.js renders as `{type: 'autogenerated', dirName: ...}`.
// Every doc in one of these becomes a sidebar entry, which is labelled from
// frontmatter `title` when present.
const AUTOGENERATED_SIDEBAR_DIRS = ['architectures', 'community'];
// frontmatter `title` when present. The list is derived from sidebars.js
// rather than restated here so a sidebar added there cannot silently escape
// the title contract.
const sidebars = (await import('../sidebars.js')).default;

const AUTOGENERATED_SIDEBAR_DIRS = [
...new Set(
Object.values(sidebars)
.flat()
.filter((entry) => entry?.type === 'autogenerated')
.map((entry) => entry.dirName),
),
].sort();

function walk(dir) {
return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
Expand Down Expand Up @@ -158,6 +169,10 @@ test('frontmatter keys are parseable key: value pairs', () => {
});

test('docs in autogenerated sidebar directories declare a title', () => {
assert.ok(
AUTOGENERATED_SIDEBAR_DIRS.length > 0,
'sidebars.js must declare at least one autogenerated sidebar, otherwise this contract asserts nothing',
);
const untitled = [];
for (const dir of AUTOGENERATED_SIDEBAR_DIRS) {
const dirDocs = docs.filter((file) =>
Expand Down