From 4aff48664fdc28c5679ba425bc9ba7786b62262c Mon Sep 17 00:00:00 2001 From: mohamed yahia Date: Fri, 24 Nov 2023 13:53:08 +0200 Subject: [PATCH] Move all the tests into a root test folder #67 --- src/{utils => lib}/databaseUtils.ts | 2 +- src/lib/indexFolder.ts | 2 +- src/lib/markdowndb.ts | 2 +- src/{utils => lib}/parseFile.ts | 1 + src/lib/process.ts | 3 +-- src/{utils => lib}/recursiveWalkDir.ts | 0 src/{utils => tests}/extractTagsFromBody.spec.ts | 2 +- src/{utils => tests}/extractWikiLinks.spec.ts | 2 +- src/{lib => tests}/markdowndb.spec.ts | 6 +++--- src/{utils => tests}/parseFile.spec.ts | 2 +- src/{lib => tests}/process.spec.ts | 2 +- src/{utils => tests}/recursiveWalkDir.spec.ts | 2 +- src/{lib => tests}/validate.spec.ts | 2 +- src/utils/index.ts | 2 -- 14 files changed, 14 insertions(+), 16 deletions(-) rename src/{utils => lib}/databaseUtils.ts (98%) rename src/{utils => lib}/parseFile.ts (99%) rename src/{utils => lib}/recursiveWalkDir.ts (100%) rename src/{utils => tests}/extractTagsFromBody.spec.ts (98%) rename src/{utils => tests}/extractWikiLinks.spec.ts (99%) rename src/{lib => tests}/markdowndb.spec.ts (98%) rename src/{utils => tests}/parseFile.spec.ts (98%) rename src/{lib => tests}/process.spec.ts (95%) rename src/{utils => tests}/recursiveWalkDir.spec.ts (92%) rename src/{lib => tests}/validate.spec.ts (91%) delete mode 100644 src/utils/index.ts diff --git a/src/utils/databaseUtils.ts b/src/lib/databaseUtils.ts similarity index 98% rename from src/utils/databaseUtils.ts rename to src/lib/databaseUtils.ts index 2becb7d..03316f4 100644 --- a/src/utils/databaseUtils.ts +++ b/src/lib/databaseUtils.ts @@ -5,7 +5,7 @@ import { MddbLink, MddbFileTag, File, -} from "../lib/schema.js"; +} from "./schema.js"; import path from "path"; import { WikiLink } from "./parseFile.js"; diff --git a/src/lib/indexFolder.ts b/src/lib/indexFolder.ts index 069f53c..6b28241 100644 --- a/src/lib/indexFolder.ts +++ b/src/lib/indexFolder.ts @@ -1,5 +1,5 @@ -import { recursiveWalkDir } from "../utils/index.js"; import { FileInfo, processFile } from "./process.js"; +import { recursiveWalkDir } from "./recursiveWalkDir.js"; export function indexFolder( folderPath: string, diff --git a/src/lib/markdowndb.ts b/src/lib/markdowndb.ts index 67002d7..4920a25 100644 --- a/src/lib/markdowndb.ts +++ b/src/lib/markdowndb.ts @@ -10,7 +10,7 @@ import { isLinkToDefined, mapFileTagsToInsert, getUniqueValues, -} from "../utils/databaseUtils.js"; +} from "./databaseUtils.js"; const defaultFilePathToUrl = (filePath: string) => { let url = filePath diff --git a/src/utils/parseFile.ts b/src/lib/parseFile.ts similarity index 99% rename from src/utils/parseFile.ts rename to src/lib/parseFile.ts index 430f359..3a26eee 100644 --- a/src/utils/parseFile.ts +++ b/src/lib/parseFile.ts @@ -30,6 +30,7 @@ export function parseFile(source: string, options?: ParsingOptions) { }; } +// Exported for testing export function processAST(source: string, options?: ParsingOptions) { const userRemarkPlugins: Array = options?.remarkPlugins || []; diff --git a/src/lib/process.ts b/src/lib/process.ts index c736f81..6a8f208 100644 --- a/src/lib/process.ts +++ b/src/lib/process.ts @@ -2,9 +2,8 @@ import crypto from "crypto"; import fs from "fs"; import path from "path"; -import { parseFile } from "../utils/index.js"; import { File } from "./schema.js"; -import { WikiLink } from "../utils/parseFile.js"; +import { WikiLink, parseFile } from "./parseFile.js"; export interface FileInfo extends File { tags: string[]; diff --git a/src/utils/recursiveWalkDir.ts b/src/lib/recursiveWalkDir.ts similarity index 100% rename from src/utils/recursiveWalkDir.ts rename to src/lib/recursiveWalkDir.ts diff --git a/src/utils/extractTagsFromBody.spec.ts b/src/tests/extractTagsFromBody.spec.ts similarity index 98% rename from src/utils/extractTagsFromBody.spec.ts rename to src/tests/extractTagsFromBody.spec.ts index bb1462a..5844a31 100644 --- a/src/utils/extractTagsFromBody.spec.ts +++ b/src/tests/extractTagsFromBody.spec.ts @@ -1,4 +1,4 @@ -import { extractTagsFromBody, processAST } from "./parseFile"; +import { extractTagsFromBody, processAST } from "../lib/parseFile"; const getTagsFromSource = (source: string) => { const ast = processAST(source, {}); diff --git a/src/utils/extractWikiLinks.spec.ts b/src/tests/extractWikiLinks.spec.ts similarity index 99% rename from src/utils/extractWikiLinks.spec.ts rename to src/tests/extractWikiLinks.spec.ts index 903c8e2..7ea439a 100644 --- a/src/utils/extractWikiLinks.spec.ts +++ b/src/tests/extractWikiLinks.spec.ts @@ -1,4 +1,4 @@ -import { extractWikiLinks, processAST } from "./parseFile"; +import { extractWikiLinks, processAST } from "../lib/parseFile"; // TODO test for links with headings and aliases ? // TODO test pdf embeds diff --git a/src/lib/markdowndb.spec.ts b/src/tests/markdowndb.spec.ts similarity index 98% rename from src/lib/markdowndb.spec.ts rename to src/tests/markdowndb.spec.ts index 585ea47..cc6375f 100644 --- a/src/lib/markdowndb.spec.ts +++ b/src/tests/markdowndb.spec.ts @@ -1,7 +1,7 @@ // import knex from "knex"; -import { MarkdownDB } from "./markdowndb"; -import { File, MddbFile, Table } from "./schema"; -import { recursiveWalkDir } from "../utils"; +import { MarkdownDB } from "../lib/markdowndb"; +import { recursiveWalkDir } from "../lib/recursiveWalkDir"; +import { File, MddbFile, Table } from "../lib/schema"; /** * @jest-environment node diff --git a/src/utils/parseFile.spec.ts b/src/tests/parseFile.spec.ts similarity index 98% rename from src/utils/parseFile.spec.ts rename to src/tests/parseFile.spec.ts index 041900e..482aaa0 100644 --- a/src/utils/parseFile.spec.ts +++ b/src/tests/parseFile.spec.ts @@ -1,4 +1,4 @@ -import { parseFile } from "./parseFile"; +import { parseFile } from "../lib/parseFile"; const source = `--- title: Hello World diff --git a/src/lib/process.spec.ts b/src/tests/process.spec.ts similarity index 95% rename from src/lib/process.spec.ts rename to src/tests/process.spec.ts index c59d8d6..936195f 100644 --- a/src/lib/process.spec.ts +++ b/src/tests/process.spec.ts @@ -1,4 +1,4 @@ -import { processFile } from "./process"; +import { processFile } from "../lib/process"; import Path from "path"; describe("Can parse a file and get file info", () => { diff --git a/src/utils/recursiveWalkDir.spec.ts b/src/tests/recursiveWalkDir.spec.ts similarity index 92% rename from src/utils/recursiveWalkDir.spec.ts rename to src/tests/recursiveWalkDir.spec.ts index bdfb2f7..eeebf37 100644 --- a/src/utils/recursiveWalkDir.spec.ts +++ b/src/tests/recursiveWalkDir.spec.ts @@ -1,4 +1,4 @@ -import { recursiveWalkDir } from "./recursiveWalkDir"; +import { recursiveWalkDir } from "../lib/recursiveWalkDir"; describe("recursiveWalkDir", () => { const contentFixturePath = "__mocks__/content/blog"; diff --git a/src/lib/validate.spec.ts b/src/tests/validate.spec.ts similarity index 91% rename from src/lib/validate.spec.ts rename to src/tests/validate.spec.ts index f4d4951..652ac79 100644 --- a/src/lib/validate.spec.ts +++ b/src/tests/validate.spec.ts @@ -1,4 +1,4 @@ -import { areUniqueObjectsByKey } from "./validate"; +import { areUniqueObjectsByKey } from "../lib/validate"; describe("areUniqueObjectsByKey", () => { test("should return true if all objects have unique values for the given key", () => { diff --git a/src/utils/index.ts b/src/utils/index.ts deleted file mode 100644 index 3646927..0000000 --- a/src/utils/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { recursiveWalkDir } from "./recursiveWalkDir.js"; -export { parseFile } from "./parseFile.js";