Skip to content
Merged
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
24 changes: 24 additions & 0 deletions site/tests/source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ const site = join(import.meta.dir, "..");
const read = async (path: string): Promise<string> =>
await readFile(join(site, path), "utf8");

function githubHeadingFragment(heading: string): string {
return heading
.trim()
.toLocaleLowerCase("en-US")
.replace(/[^\p{L}\p{N}\s-]/gu, "")
.replace(/\s+/gu, "-");
}

function record(value: unknown, label: string): Readonly<Record<string, unknown>> {
if (typeof value !== "object" || value === null || Array.isArray(value)) {
throw new TypeError(`${label} must be an object.`);
Expand Down Expand Up @@ -130,6 +138,22 @@ describe("Oh site source contract", () => {
expect(home).toContain('className="text-action" href="/spec"');
});

test("links the install action to an existing README heading", async () => {
const [home, readme] = await Promise.all([
read("app/page.tsx"),
readFile(join(site, "..", "README.md"), "utf8"),
]);
const installLink = home.match(
/href="https:\/\/github\.com\/hraness\/oh#([^"#]+)"/u,
);
const installFragment = installLink?.[1] ?? "";
const readmeFragments = [...readme.matchAll(/^#{1,6}\s+(.+?)\s*#*$/gmu)]
.map(([, heading]) => githubHeadingFragment(heading ?? ""));

expect(installFragment).toBe("install-and-first-run");
expect(readmeFragments).toContain(installFragment);
});

test("derives public contract identity, version, and status from mirrored data", async () => {
const [home, specification] = await Promise.all([
read("app/page.tsx"),
Expand Down