Skip to content

Commit

Permalink
Fix some test issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ptgott committed Jul 8, 2024
1 parent 7a350dd commit 50ed6d8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
1 change: 1 addition & 0 deletions server/remark-toc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as nodeFS from "fs";
import "path";

export const resolveTOCIncludes = (dirPath: string, fs = nodeFS) => {
const parts = path.parse(dirPath);
Expand Down
101 changes: 54 additions & 47 deletions uvu-tests/remark-toc.test.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,102 @@
import { Volume, createFsFromVolume } from "memfs";
import { resolveTOCIncludes } from "../server/remark-toc";
import { suite } from "uvu";
import * as assert from "uvu/assert";

describe("generate a menu page", () => {
const testFilesTwoSections = {
"/docs/docs.mdx": `---
const Suite = suite("server/remark-toc");

const testFilesTwoSections = {
"/docs/docs.mdx": `---
title: "Documentation Home"
description: "Guides to setting up the product."
---
Guides to setting up the product.
`,
"/docs/database-access/database-access.mdx": `---
"/docs/database-access/database-access.mdx": `---
title: "Database Access"
description: "Guides related to Database Access."
---
Guides related to Database Access.
`,
"/docs/database-access/page1.mdx": `---
"/docs/database-access/page1.mdx": `---
title: "Database Access Page 1"
description: "Protecting DB 1 with Teleport"
---`,
"/docs/database-access/page2.mdx": `---
"/docs/database-access/page2.mdx": `---
title: "Database Access Page 2"
description: "Protecting DB 2 with Teleport"
---`,
"/docs/application-access/application-access.mdx": `---
"/docs/application-access/application-access.mdx": `---
title: "Application Access"
description: "Guides related to Application Access"
---
Guides related to Application Access.
`,
"/docs/application-access/page1.mdx": `---
"/docs/application-access/page1.mdx": `---
title: "Application Access Page 1"
description: "Protecting App 1 with Teleport"
---`,
"/docs/application-access/page2.mdx": `---
"/docs/application-access/page2.mdx": `---
title: "Application Access Page 2"
description: "Protecting App 2 with Teleport"
---`,
};
};

test("one link to a directory", () => {
const expected = `
Suite("one link to a directory", () => {
const expected = `
- [Application Access](application-access/application-access.mdx) (section): Guides related to Application Access
`;

const vol = Volume.fromJSON({
"/docs/docs.mdx": `---
const vol = Volume.fromJSON({
"/docs/docs.mdx": `---
title: Documentation Home
description: Guides for setting up the product.
---
Guides for setting up the product.
`,
"/docs/application-access/application-access.mdx": `---
"/docs/application-access/application-access.mdx": `---
title: "Application Access"
description: "Guides related to Application Access"
---
`,
"/docs/application-access/page1.mdx": `---
"/docs/application-access/page1.mdx": `---
title: "Application Access Page 1"
description: "Protecting App 1 with Teleport"
---`,
"/docs/application-access/page2.mdx": `---
"/docs/application-access/page2.mdx": `---
title: "Application Access Page 2"
description: "Protecting App 2 with Teleport"
---`,
});
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
expect(actual).toBe(expected);
});
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
assert.equal(actual, expected);
});

test("multiple links to directories", () => {
const expected = `- [Application Access](application-access/application-access.mdx) (section): Guides related to Application Access
Suite("multiple links to directories", () => {
const expected = `- [Application Access](application-access/application-access.mdx) (section): Guides related to Application Access
- [Database Access](database-access/database-access.mdx): Guides related to Database Access
`;

const vol = Volume.fromJSON(testFilesTwoSections);
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
expect(actual).toBe(expected);
});
const vol = Volume.fromJSON(testFilesTwoSections);
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
assert.equal(actual, expected);
});

test(`throws an error on a generated menu page that does not correspond to a subdirectory`, () => {
Suite(
`throws an error on a generated menu page that does not correspond to a subdirectory`,
() => {
const vol = Volume.fromJSON({
"/docs/docs.mdx": `---
title: "Documentation Home"
Expand All @@ -118,66 +123,68 @@ description: "Guides related to JWTs"
});

const fs = createFsFromVolume(vol);
expect(() => {
assert.throws(() => {
const actual = resolveTOCIncludes("/docs/", fs);
}).toThrow("jwt.mdx");
});
}, "jwt.mdx");
}
);

test("orders sections correctly", () => {
const expected = `
Suite("orders sections correctly", () => {
const expected = `
- [Application Access](application-access/application-access.mdx) (section): Guides related to Application Access
- [Desktop Access](desktop-access/database-access.mdx) (seciton): Guides related to Desktop Access
- [API Usage](api.mdx): Using the API.
- [Initial Setup](initial-setup.mdx): How to set up the product for the first time.
- [Kubernetes](kubernetes.mdx): A guide related to Kubernetes.
`;

const vol = Volume.fromJSON({
"/docs/docs.mdx": `---
const vol = Volume.fromJSON({
"/docs/docs.mdx": `---
title: Documentation Home
description: Guides to setting up the product.
---
Guides to setting up the product.
`,
"/docs/desktop-access/desktop-access.mdx": `---
"/docs/desktop-access/desktop-access.mdx": `---
title: "Desktop Access"
description: "Guides related to Desktop Access"
---
`,

"/docs/application-access/application-access.mdx": `---
"/docs/application-access/application-access.mdx": `---
title: "Application Access"
description: "Guides related to Application Access"
---
`,
"/docs/desktop-access/get-started.mdx": `---
"/docs/desktop-access/get-started.mdx": `---
title: "Get Started"
description: "Get started with desktop access."
---`,
"/docs/application-access/page1.mdx": `---
"/docs/application-access/page1.mdx": `---
title: "Application Access Page 1"
description: "Protecting App 1 with Teleport"
---`,
"/docs/kubernetes.mdx": `---
"/docs/kubernetes.mdx": `---
title: "Kubernetes"
description: "A guide related to Kubernetes."
---`,

"/docs/initial-setup.mdx": `---
"/docs/initial-setup.mdx": `---
title: "Initial Setup"
description: "How to set up the product for the first time."
---`,
"/docs/api.mdx": `---
"/docs/api.mdx": `---
title: "API Usage"
description: "Using the API."
---`,
});
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
expect(actual).toBe(expected);
});
const fs = createFsFromVolume(vol);
const actual = resolveTOCIncludes("/docs/", fs);
assert.equal(actual, expected);
});

Suite.run();

0 comments on commit 50ed6d8

Please sign in to comment.