| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { isRepoDoc, pickRepoDocs, repoDocTitle } from "./repo-docs.ts"; |
| 5 | |
| 6 | test("a project's docs are Markdown under docs/ and the README at the root", () => { |
| 7 | assert.ok(isRepoDoc("README.md")); |
| 8 | assert.ok(isRepoDoc("docs/guide/setup.md")); |
| 9 | assert.ok(isRepoDoc("docs/a.mdx")); |
| 10 | assert.ok(!isRepoDoc("src/README.md")); |
| 11 | assert.ok(!isRepoDoc("docs/logo.png")); |
| 12 | assert.ok(!isRepoDoc("documentation/a.md")); |
| 13 | assert.deepEqual( |
| 14 | pickRepoDocs([{ path: "docs/b.md" }, { path: "src/x.ts" }, { path: "docs/a.md" }, { path: "README.md" }]).map((f) => f.path), |
| 15 | ["README.md", "docs/a.md", "docs/b.md"], |
| 16 | ); |
| 17 | }); |
| 18 | |
| 19 | test("a file's title is its front matter's, its first heading, or its name", () => { |
| 20 | assert.equal(repoDocTitle("docs/a.md", "---\ntitle: \"Setting up\"\n---\n# Other"), "Setting up"); |
| 21 | assert.equal(repoDocTitle("docs/a.md", "Intro\n\n# The **real** title\n"), "The real title"); |
| 22 | assert.equal(repoDocTitle("docs/getting-started.md", "no heading"), "Getting started"); |
| 23 | assert.equal(repoDocTitle("README.md", "text"), "README"); |
| 24 | assert.equal(repoDocTitle("docs/deploy/README.md", "text"), "deploy"); |
| 25 | }); |