From 50ed6d8388d218ed391ddb3fd2db36015564ff89 Mon Sep 17 00:00:00 2001 From: Paul Gottschling Date: Mon, 8 Jul 2024 11:11:59 -0400 Subject: [PATCH] Fix some test issues --- server/remark-toc.ts | 1 + uvu-tests/remark-toc.test.ts | 101 +++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 47 deletions(-) diff --git a/server/remark-toc.ts b/server/remark-toc.ts index 690975a8bc..e854803340 100644 --- a/server/remark-toc.ts +++ b/server/remark-toc.ts @@ -1,4 +1,5 @@ import * as nodeFS from "fs"; +import "path"; export const resolveTOCIncludes = (dirPath: string, fs = nodeFS) => { const parts = path.parse(dirPath); diff --git a/uvu-tests/remark-toc.test.ts b/uvu-tests/remark-toc.test.ts index 5e334c423c..1868b6affd 100644 --- a/uvu-tests/remark-toc.test.ts +++ b/uvu-tests/remark-toc.test.ts @@ -1,9 +1,12 @@ 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." --- @@ -11,7 +14,7 @@ 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." --- @@ -19,15 +22,15 @@ 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" --- @@ -35,24 +38,24 @@ 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. --- @@ -60,38 +63,40 @@ 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" @@ -118,13 +123,14 @@ 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. @@ -132,8 +138,8 @@ description: "Guides related to JWTs" - [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. --- @@ -141,43 +147,44 @@ 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();