Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(test): tests that got broken along the way
Elian Doran2b966afbe1f0
diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.tsindex 9623f0172e..2867923258 100644--- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts+++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts@@ -39,8 +39,8 @@ describe("Building events", () => {it("supports custom start date", async () => {const noteIds = buildNotes([- { title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "#myStartDate" },- { title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "#myStartDate" },+ { title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "myStartDate" },+ { title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "myStartDate" },]);const events = await CalendarView.buildEvents(noteIds);@@ -59,10 +59,10 @@ describe("Building events", () => {it("supports custom start date and end date", async () => {const noteIds = buildNotes([- { title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" },- { title: "Note 2", "#myStartDate": "2025-05-07", "#endDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" },- { title: "Note 3", "#startDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" },- { title: "Note 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" },+ { title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" },+ { title: "Note 2", "#myStartDate": "2025-05-07", "#endDate": "2025-05-08", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" },+ { title: "Note 3", "#startDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" },+ { title: "Note 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "myStartDate", "#calendar:endDate": "myEndDate" },]);const events = await CalendarView.buildEvents(noteIds);@@ -75,8 +75,8 @@ describe("Building events", () => {it("supports label as custom title", async () => {const noteIds = buildNotes([- { title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#calendar:title": "#myTitle" },- { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "#myTitle" },+ { title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#calendar:title": "myTitle" },+ { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" },]);const events = await CalendarView.buildEvents(noteIds);@@ -88,8 +88,8 @@ describe("Building events", () => {it("supports relation as custom title", async () => {const noteIds = buildNotes([{ id: "mySharedTitle", title: "My shared title" },- { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },- { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },+ { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "myTitle" },+ { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" },]);const events = await CalendarView.buildEvents(noteIds);@@ -100,23 +100,9 @@ describe("Building events", () => {it("supports relation as custom title with custom label", async () => {const noteIds = buildNotes([- { id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "#myTitle" },- { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },- { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },- ]);- const events = await CalendarView.buildEvents(noteIds);-- expect(events).toHaveLength(2);- expect(events[0]).toMatchObject({ title: "My shared custom title", start: "2025-05-05" });- expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });- });-- it("discards relation as custom title with custom relation", async () => {- const noteIds = buildNotes([- { id: "myParentNote", title: "My parent note" },- { id: "mySharedTitle", title: "My custom title", "~myTitle": "myParentNote", "#calendar:title": "~myTitle" },- { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },- { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },+ { id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "myTitle" },+ { title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "myTitle" },+ { title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "myTitle" },]);const events = await CalendarView.buildEvents(noteIds);@@ -135,15 +121,15 @@ describe("Promoted attributes", () => {"#mood": "happy","#label:weight": "promoted,number,single,precision=1","#label:mood": "promoted,alias=Mood,single,text",- "#calendar:promotedAttributes": "label:weight,label:mood"+ "#calendar:displayedAttributes": "weight,mood"});const event = await CalendarView.buildEvent(note, "2025-04-04");expect(event).toHaveLength(1);- expect(event[0]?.promotedAttributes).toMatchObject({- weight: "75",- Mood: "happy"- })+ expect(event[0]?.promotedAttributes).toMatchObject([+ [ "weight", "75" ],+ [ "mood", "happy" ]+ ]);});it("supports relations", async () => {@@ -152,14 +138,14 @@ describe("Promoted attributes", () => {"~assignee": buildNote({"title": "Target note"}).noteId,- "#calendar:promotedAttributes": "relation:assignee",+ "#calendar:displayedAttributes": "assignee","#relation:assignee": "promoted,alias=Assignee,single,text",});const event = await CalendarView.buildEvent(note, "2025-04-04");expect(event).toHaveLength(1);- expect(event[0]?.promotedAttributes).toMatchObject({- "Assignee": "Target note"- })+ expect(event[0]?.promotedAttributes).toMatchObject([+ [ "assignee", "Target note" ]+ ])});});diff --git a/src/services/data_dir.spec.ts b/src/services/data_dir.spec.tsindex 4c94cbe940..24315a5ff8 100644--- a/src/services/data_dir.spec.ts+++ b/src/services/data_dir.spec.ts@@ -272,7 +272,7 @@ describe("data_dir.ts unit tests", async () => {});describe("#getDataDirs()", () => {- const envKeys: Omit<keyof ReturnType<typeof getDataDirs>, "TRILIUM_DATA_DIR">[] = ["DOCUMENT_PATH", "BACKUP_DIR", "LOG_DIR", "ANONYMIZED_DB_DIR", "CONFIG_INI_PATH"];+ const envKeys: Omit<keyof ReturnType<typeof getDataDirs>, "TRILIUM_DATA_DIR">[] = ["DOCUMENT_PATH", "BACKUP_DIR", "LOG_DIR", "ANONYMIZED_DB_DIR", "CONFIG_INI_PATH", "TMP_DIR"];const setMockedEnv = (prefix: string | null) => {envKeys.forEach((key) => {diff --git a/src/services/import/markdown.spec.ts b/src/services/import/markdown.spec.tsindex dc382b8962..5d5ccd33ce 100644--- a/src/services/import/markdown.spec.ts+++ b/src/services/import/markdown.spec.ts@@ -40,12 +40,7 @@ describe("markdown", () => {# another oneHello, world`, "title");- expect(result).toBe(trimIndentation`\- <h2>Hello</h2>- <h2>world</h2>- <h2>another one</h2>- <p>Hello, world</p>- `);+ expect(result).toBe(`<h2>Hello</h2><h2>world</h2><h2>another one</h2><p>Hello, world</p>`);});@@ -54,7 +49,7 @@ describe("markdown", () => {# What's newHi there`, "What's new")- expect(result).toBe(`\n<p>Hi there</p>\n`);+ expect(result).toBe(`<p>Hi there</p>`);});it("trims unnecessary whitespace", () => {diff --git a/src/services/import/single.spec.ts b/src/services/import/single.spec.tsindex e04b657df5..1eacd261bd 100644--- a/src/services/import/single.spec.ts+++ b/src/services/import/single.spec.ts@@ -87,7 +87,7 @@ describe("processNoteContent", () => {it("supports markdown note with UTF-16", async () => {const { importedNote } = await testImport("UTF-16LE Text Note.md", "text/markdown");expect(importedNote.mime).toBe("text/html");- expect(importedNote.getContent().toString()).toBe("<h2>Hello world</h2>\n<p>Plain text goes here.</p>\n");+ expect(importedNote.getContent().toString()).toBe("<h2>Hello world</h2><p>Plain text goes here.</p>");});it("supports excalidraw note", async () => {diff --git a/src/services/in_app_help.ts b/src/services/in_app_help.tsindex b7fd300501..7841ee71b1 100644--- a/src/services/in_app_help.ts+++ b/src/services/in_app_help.ts@@ -13,9 +13,9 @@ export function getHelpHiddenSubtreeData() {const appDir = path.join(srcRoot, "public", isDev ? "app" : "app-dist");const helpDir = path.join(appDir, "doc_notes", "en", "User Guide");const metaFilePath = path.join(helpDir, "!!!meta.json");- const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8"));try {+ const metaFileContent = JSON.parse(fs.readFileSync(metaFilePath).toString("utf-8"));return parseNoteMetaFile(metaFileContent as NoteMetaFile);} catch (e) {console.warn(e);diff --git a/src/share/routes.spec.ts b/src/share/routes.spec.tsindex 86e1927bdd..c78e447af3 100644--- a/src/share/routes.spec.ts+++ b/src/share/routes.spec.ts@@ -27,6 +27,7 @@ describe("Share API test", () => {it("requests password for password-protected share", async () => {await supertest(app).get("/share/YjlPRj2E9fOV")+ .expect(200).expect("WWW-Authenticate", 'Basic realm="User Visible Realm", charset="UTF-8"');expect(cannotSetHeadersCount).toBe(0);});diff --git a/src/share/routes.ts b/src/share/routes.tsindex 3c6db87d54..2591cce0cf 100644--- a/src/share/routes.ts+++ b/src/share/routes.ts@@ -131,6 +131,7 @@ function renderImageAttachment(image: SNote, res: Response, attachmentName: strifunction register(router: Router) {function renderNote(note: SNote, req: Request, res: Response) {if (!note) {+ console.log("Unable to find note ", note);res.status(404).render("share/404");return;}@@ -215,6 +216,7 @@ function register(router: Router) {const { shareId } = req.params;+ console.log("Got share ", shareId, shaca.notes, shaca.aliasToNote);const note = shaca.aliasToNote[shareId] || shaca.notes[shareId];renderNote(note, req, res);