diff --git a/apps/client/src/components/app_context.ts b/apps/client/src/components/app_context.ts index 2ad4003f5..004d1ef66 100644 --- a/apps/client/src/components/app_context.ts +++ b/apps/client/src/components/app_context.ts @@ -6,7 +6,7 @@ import { ColumnComponent } from "tabulator-tables"; import type { Attribute } from "../services/attribute_parser.js"; import froca from "../services/froca.js"; -import { initLocale,t } from "../services/i18n.js"; +import { initLocale, t } from "../services/i18n.js"; import keyboardActionsService from "../services/keyboard_actions.js"; import linkService, { type ViewScope } from "../services/link.js"; import type LoadResults from "../services/load_results.js"; diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.ts index 4fcdbf806..048d175db 100644 --- a/apps/client/src/entities/fnote.ts +++ b/apps/client/src/entities/fnote.ts @@ -8,7 +8,7 @@ import search from "../services/search.js"; import server from "../services/server.js"; import utils from "../services/utils.js"; import type FAttachment from "./fattachment.js"; -import type { AttributeType,default as FAttribute } from "./fattribute.js"; +import type { AttributeType, default as FAttribute } from "./fattribute.js"; const LABEL = "label"; const RELATION = "relation"; diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.ts index 89f1853dc..af01cf863 100644 --- a/apps/client/src/widgets/type_widgets/text/config.spec.ts +++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts @@ -35,5 +35,5 @@ describe("CK config", () => { expect(config.translations, locale.id).toHaveLength(2); } } - }, 10_000); + }, 20_000); }); diff --git a/apps/client/tsconfig.spec.json b/apps/client/tsconfig.spec.json index 152d9cb27..43317d4e0 100644 --- a/apps/client/tsconfig.spec.json +++ b/apps/client/tsconfig.spec.json @@ -3,8 +3,6 @@ "compilerOptions": { "outDir": "./out-tsc/vitest", "types": [ - "vitest/importMeta", - "vite/client", "node", "vitest" ], diff --git a/apps/server-e2e/src/note_types/pdf.spec.ts b/apps/server-e2e/src/note_types/pdf.spec.ts index ff1cd7dbc..99fe02173 100644 --- a/apps/server-e2e/src/note_types/pdf.spec.ts +++ b/apps/server-e2e/src/note_types/pdf.spec.ts @@ -1,5 +1,3 @@ -import { describe } from "node:test"; - import test, { BrowserContext, expect, Page } from "@playwright/test"; import App from "../support/app"; @@ -10,92 +8,88 @@ test.beforeEach(async ({ page, context }) => { }); test.afterEach(async ({ page, context }) => await setLayout({ page, context }, false)); -describe("PDF sidebar", () => { +test("Table of contents works", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + await app.goToNoteInNewTab("Dacia Logan.pdf"); - test("Table of contents works", async ({ page, context }) => { - const app = new App(page, context); - await app.goto(); - await app.goToNoteInNewTab("Dacia Logan.pdf"); + const toc = app.sidebar.locator(".toc"); - const toc = app.sidebar.locator(".toc"); + await expect(toc.locator("li")).toHaveCount(48); + await expect(toc.locator("li", { hasText: "Logan Van" })).toHaveCount(1); - await expect(toc.locator("li")).toHaveCount(48); - await expect(toc.locator("li", { hasText: "Logan Van" })).toHaveCount(1); + const pdfHelper = new PdfHelper(app); + await toc.locator("li", { hasText: "Logan Pick-Up" }).click(); + await pdfHelper.expectPageToBe(13); - const pdfHelper = new PdfHelper(app); - await toc.locator("li", { hasText: "Logan Pick-Up" }).click(); - await pdfHelper.expectPageToBe(13); - - await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); - await expect(toc.locator("li")).toHaveCount(0); - }); - - test("Page navigation works", async ({ page, context }) => { - const app = new App(page, context); - await app.goto(); - await app.goToNoteInNewTab("Dacia Logan.pdf"); - - const pagesList = app.sidebar.locator(".pdf-pages-list"); - - // Check count is correct. - await expect(app.sidebar).toContainText("28 pages"); - expect(await pagesList.locator(".pdf-page-item").count()).toBe(28); - - // Go to page 3. - await pagesList.locator(".pdf-page-item").nth(2).click(); - - const pdfHelper = new PdfHelper(app); - await pdfHelper.expectPageToBe(3); - - await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); - await expect(pagesList.locator(".pdf-page-item")).toHaveCount(1); - }); - - test("Attachments listing works", async ({ page, context }) => { - const app = new App(page, context); - await app.goto(); - await app.goToNoteInNewTab("Dacia Logan.pdf"); - - const attachmentsList = app.sidebar.locator(".pdf-attachments-list"); - await expect(app.sidebar).toContainText("2 attachments"); - await expect(attachmentsList.locator(".pdf-attachment-item")).toHaveCount(2); - - const attachmentInfo = attachmentsList.locator(".pdf-attachment-item", { hasText: "Note.trilium" }); - await expect(attachmentInfo).toContainText("3.36 MiB"); - - // Download the attachment and check its size. - const [ download ] = await Promise.all([ - page.waitForEvent("download"), - attachmentInfo.locator(".bx-download").click() - ]); - expect(download).toBeDefined(); - - await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); - await expect(attachmentsList.locator(".pdf-attachment-item")).toHaveCount(0); - }); - - test("Layers listing works", async ({ page, context }) => { - const app = new App(page, context); - await app.goto(); - await app.goToNoteInNewTab("Layers test.pdf"); - - // Check count is correct. - await expect(app.sidebar).toContainText("2 layers"); - const layersList = app.sidebar.locator(".pdf-layers-list"); - await expect(layersList.locator(".pdf-layer-item")).toHaveCount(2); - - // Toggle visibility of the first layer. - const firstLayer = layersList.locator(".pdf-layer-item").first(); - await expect(firstLayer).toContainText("Tongue out"); - await expect(firstLayer).toContainClass("hidden"); - await firstLayer.click(); - await expect(firstLayer).not.toContainClass("visible"); - - await app.clickNoteOnNoteTreeByTitle("Dacia Logan.pdf"); - await expect(layersList.locator(".pdf-layer-item")).toHaveCount(0); - }); + await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); + await expect(toc.locator("li")).toHaveCount(0); }); +test("Page navigation works", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + await app.goToNoteInNewTab("Dacia Logan.pdf"); + + const pagesList = app.sidebar.locator(".pdf-pages-list"); + + // Check count is correct. + await expect(app.sidebar).toContainText("28 pages"); + expect(await pagesList.locator(".pdf-page-item").count()).toBe(28); + + // Go to page 3. + await pagesList.locator(".pdf-page-item").nth(2).click(); + + const pdfHelper = new PdfHelper(app); + await pdfHelper.expectPageToBe(3); + + await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); + await expect(pagesList.locator(".pdf-page-item")).toHaveCount(1); +}); + +test("Attachments listing works", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + await app.goToNoteInNewTab("Dacia Logan.pdf"); + + const attachmentsList = app.sidebar.locator(".pdf-attachments-list"); + await expect(app.sidebar).toContainText("2 attachments"); + await expect(attachmentsList.locator(".pdf-attachment-item")).toHaveCount(2); + + const attachmentInfo = attachmentsList.locator(".pdf-attachment-item", { hasText: "Note.trilium" }); + await expect(attachmentInfo).toContainText("3.36 MiB"); + + // Download the attachment and check its size. + const [ download ] = await Promise.all([ + page.waitForEvent("download"), + attachmentInfo.locator(".bx-download").click() + ]); + expect(download).toBeDefined(); + + await app.clickNoteOnNoteTreeByTitle("Layers test.pdf"); + await expect(attachmentsList.locator(".pdf-attachment-item")).toHaveCount(0); +}); + +test("Layers listing works", async ({ page, context }) => { + const app = new App(page, context); + await app.goto(); + await app.goToNoteInNewTab("Layers test.pdf"); + + // Check count is correct. + await expect(app.sidebar).toContainText("2 layers"); + const layersList = app.sidebar.locator(".pdf-layers-list"); + await expect(layersList.locator(".pdf-layer-item")).toHaveCount(2); + + // Toggle visibility of the first layer. + const firstLayer = layersList.locator(".pdf-layer-item").first(); + await expect(firstLayer).toContainText("Tongue out"); + await expect(firstLayer).toContainClass("hidden"); + await firstLayer.click(); + await expect(firstLayer).not.toContainClass("visible"); + + await app.clickNoteOnNoteTreeByTitle("Dacia Logan.pdf"); + await expect(layersList.locator(".pdf-layer-item")).toHaveCount(0); +}); async function setLayout({ page, context}: { page: Page; context: BrowserContext }, newLayout: boolean) { const app = new App(page, context); diff --git a/apps/server/src/becca/entities/brevision.spec.ts b/apps/server/src/becca/entities/brevision.spec.ts index 176ee66c0..1181c956c 100644 --- a/apps/server/src/becca/entities/brevision.spec.ts +++ b/apps/server/src/becca/entities/brevision.spec.ts @@ -1,3 +1,5 @@ +import { describe, expect, it } from "vitest"; + import BRevision from "./brevision.js"; describe("Revision", () => { diff --git a/apps/server/src/becca/similarity.spec.ts b/apps/server/src/becca/similarity.spec.ts index 4809e1f13..f7f9df909 100644 --- a/apps/server/src/becca/similarity.spec.ts +++ b/apps/server/src/becca/similarity.spec.ts @@ -1,4 +1,6 @@ import { trimIndentation } from "@triliumnext/commons"; +import { describe, expect, it } from "vitest"; + import { buildNote } from "../test/becca_easy_mocking"; import { buildRewardMap } from "./similarity"; diff --git a/apps/server/src/routes/api/clipper.spec.ts b/apps/server/src/routes/api/clipper.spec.ts index 4bfac679e..693b831a6 100644 --- a/apps/server/src/routes/api/clipper.spec.ts +++ b/apps/server/src/routes/api/clipper.spec.ts @@ -1,3 +1,5 @@ +import { beforeAll, describe, expect, it, vi } from "vitest"; + import BNote from '../../becca/entities/bnote.js'; import cls from "../../services/cls"; import { buildNote } from "../../test/becca_easy_mocking"; @@ -17,7 +19,7 @@ describe("processContent", () => { return { attachmentId: "foo", title: "encodedTitle", - } + }; } } })); @@ -25,12 +27,12 @@ describe("processContent", () => { it("processes basic note", () => { const processed = cls.init(() => processContent([], note, "
Hello world.
")); - expect(processed).toStrictEqual("Hello world.
") + expect(processed).toStrictEqual("Hello world.
"); }); it("processes plain text", () => { const processed = cls.init(() => processContent([], note, "Hello world.")); - expect(processed).toStrictEqual("Hello world.
") + expect(processed).toStrictEqual("Hello world.
"); }); it("replaces images", () => { diff --git a/apps/server/src/routes/api/llm.spec.ts b/apps/server/src/routes/api/llm.spec.ts index 846b9ecc9..e3c1255dc 100644 --- a/apps/server/src/routes/api/llm.spec.ts +++ b/apps/server/src/routes/api/llm.spec.ts @@ -1,9 +1,10 @@ -import { Application } from "express"; -import { beforeAll, describe, expect, it, vi, beforeEach, afterEach } from "vitest"; -import supertest from "supertest"; -import config from "../../services/config.js"; -import { refreshAuth } from "../../services/auth.js"; import { sleepFor } from "@triliumnext/commons"; +import { Application } from "express"; +import supertest from "supertest"; +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; + +import { refreshAuth } from "../../services/auth.js"; +import config from "../../services/config.js"; // Mock the CSRF protection middleware to allow tests to pass vi.mock("../csrf_protection.js", () => ({ @@ -841,7 +842,7 @@ describe("LLM API Tests", () => { try { await supertest(app) .delete(`/api/llm/chat/${createdChatId}`) - ; + ; } catch (error) { // Ignore cleanup errors } diff --git a/apps/server/src/routes/api/note_map.spec.ts b/apps/server/src/routes/api/note_map.spec.ts index 0ab5d1d2d..6d37ce269 100644 --- a/apps/server/src/routes/api/note_map.spec.ts +++ b/apps/server/src/routes/api/note_map.spec.ts @@ -1,4 +1,6 @@ import { trimIndentation } from "@triliumnext/commons"; +import { describe, expect, it } from "vitest"; + import { buildNote, buildNotes } from "../../test/becca_easy_mocking"; import note_map from "./note_map"; diff --git a/apps/server/src/routes/login.spec.ts b/apps/server/src/routes/login.spec.ts index 07451ec43..0f210bfdc 100644 --- a/apps/server/src/routes/login.spec.ts +++ b/apps/server/src/routes/login.spec.ts @@ -1,10 +1,11 @@ -import { beforeAll, describe, expect, it } from "vitest"; -import supertest, { type Response } from "supertest"; -import type { Application } from "express"; import { dayjs } from "@triliumnext/commons"; -import { type SQLiteSessionStore } from "./session_parser.js"; +import type { Application } from "express"; import { SessionData } from "express-session"; +import supertest, { type Response } from "supertest"; +import { beforeAll, describe, expect, it, vi } from "vitest"; + import cls from "../services/cls.js"; +import { type SQLiteSessionStore } from "./session_parser.js"; let app: Application; let sessionStore: SQLiteSessionStore; @@ -24,7 +25,7 @@ describe("Login Route test", () => { // RegExp for login page specific string in HTML const res = await supertest(app) .get("/login") - .expect(200) + .expect(200); expect(res.text).toMatch(/assets\/v[0-9.a-z]+\/src\/login\.js/); @@ -35,7 +36,7 @@ describe("Login Route test", () => { await supertest(app) .post("/login") .send({ password: "fakePassword" }) - .expect(401) + .expect(401); }); @@ -69,7 +70,7 @@ describe("Login Route test", () => { // ignore the seconds in the comparison, just to avoid flakiness in tests, // if for some reason execution is slow between calculation of expected and actual - expect(actualExpiresDate.slice(0,23)).toBe(expectedExpiresDate.slice(0,23)) + expect(actualExpiresDate.slice(0,23)).toBe(expectedExpiresDate.slice(0,23)); }); it("sets the correct sesssion data", async () => { @@ -121,14 +122,14 @@ describe("Login Route test", () => { res = await supertest(app) .post("/login") .send({ password: "demo1234" }) - .expect(302) + .expect(302); setCookieHeader = res.headers["set-cookie"][0]; }); it("does not set Expires", async () => { // match for e.g. "Expires=Wed, 07 May 2025 07:02:59 GMT;" - expect(setCookieHeader).not.toMatch(/Expires=(?