From 51790b3926b8b839bae7b92fdd46bfd91b6b8b1d Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 8 Mar 2025 20:48:03 -0800 Subject: [PATCH] fix tests --- package.json | 2 +- quartz/util/fileTrie.test.ts | 11 ++++++----- quartz/util/fileTrie.ts | 12 +++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 069c3b0c6..794a67a6c 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "docs": "npx quartz build --serve -d docs", "check": "tsc --noEmit && npx prettier . --check", "format": "npx prettier . --write", - "test": "for f in $(find ./quartz -name '*.test.ts'); do tsx $f; done", + "test": "tsx --test \"./quartz/**/*.test.ts\"", "profile": "0x -D prof ./quartz/bootstrap-cli.mjs build --concurrency=1" }, "engines": { diff --git a/quartz/util/fileTrie.test.ts b/quartz/util/fileTrie.test.ts index e1709bf50..3de3d93dd 100644 --- a/quartz/util/fileTrie.test.ts +++ b/quartz/util/fileTrie.test.ts @@ -127,19 +127,20 @@ describe("FileTrie", () => { describe("entries", () => { test("should return all entries", () => { const data1 = { title: "Test1", slug: "test1" } - const data2 = { title: "Test2", slug: "test2" } + const data2 = { title: "Test2", slug: "a/b/test2" } trie.add(data1) trie.add(data2) const entries = trie.entries() - assert.strictEqual(entries.length, 3) assert.deepStrictEqual( entries.map(([path, node]) => [path, node.data]), [ ["", trie.data], - ["test1/index", data1], - ["test2/index", data2], + ["test1", data1], + ["a/index", null], + ["a/b/index", null], + ["a/b/test2", data2], ], ) }) @@ -165,7 +166,7 @@ describe("FileTrie", () => { trie.add(data3) const paths = trie.getFolderPaths() - assert.deepStrictEqual(paths, ["folder", "folder/subfolder", "abc"]) + assert.deepStrictEqual(paths, ["folder/index", "folder/subfolder/index", "abc/index"]) }) }) diff --git a/quartz/util/fileTrie.ts b/quartz/util/fileTrie.ts index dd21d3231..e0bf58b61 100644 --- a/quartz/util/fileTrie.ts +++ b/quartz/util/fileTrie.ts @@ -103,12 +103,14 @@ export class FileTrieNode { currentPath: string, ): [FullSlug, FileTrieNode][] => { const segments = [currentPath, node.slugSegment] - if (node.isFolder && node.depth > 0) { - segments.push("index") - } - const fullPath = joinSegments(...segments) as FullSlug - const result: [FullSlug, FileTrieNode][] = [[fullPath, node]] + + const indexQualifiedPath = node.isFolder && node.depth > 0 ? + joinSegments(fullPath, "index") as FullSlug : + fullPath + + const result: [FullSlug, FileTrieNode][] = [[indexQualifiedPath, node]] + return result.concat(...node.children.map((child) => traverse(child, fullPath))) }