Clean up Vite (#8238)

This commit is contained in:
Elian Doran 2026-01-02 00:36:46 +02:00 committed by GitHub
commit ff82d9c38c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 150 additions and 142 deletions

View File

@ -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";

View File

@ -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";

View File

@ -35,5 +35,5 @@ describe("CK config", () => {
expect(config.translations, locale.id).toHaveLength(2);
}
}
}, 10_000);
}, 20_000);
});

View File

@ -3,8 +3,6 @@
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/importMeta",
"vite/client",
"node",
"vitest"
],

View File

@ -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);

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import BRevision from "./brevision.js";
describe("Revision", () => {

View File

@ -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";

View File

@ -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, "<p>Hello world.</p>"));
expect(processed).toStrictEqual("<p>Hello world.</p>")
expect(processed).toStrictEqual("<p>Hello world.</p>");
});
it("processes plain text", () => {
const processed = cls.init(() => processContent([], note, "Hello world."));
expect(processed).toStrictEqual("<p>Hello world.</p>")
expect(processed).toStrictEqual("<p>Hello world.</p>");
});
it("replaces images", () => {

View File

@ -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
}

View File

@ -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";

View File

@ -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=(?<date>[\w\s,:]+)/)
expect(setCookieHeader).not.toMatch(/Expires=(?<date>[\w\s,:]+)/);
});
it("stores the session in the database", async () => {

View File

@ -1,9 +1,11 @@
import supertest from "supertest";
import options from "./options";
import cls from "./cls";
import { Application } from "express";
import config from "./config";
import supertest from "supertest";
import { beforeAll, describe, expect, it } from "vitest";
import { refreshAuth } from "./auth";
import cls from "./cls";
import config from "./config";
import options from "./options";
let app: Application;
@ -39,7 +41,7 @@ describe("Auth", () => {
const response = await supertest(app)
.get("/")
.redirects(1)
.expect(200)
.expect(200);
expect(response.text).not.toContain(`id="totpToken"`);
});
});

View File

@ -1,11 +1,12 @@
import { describe, it, expect } from "vitest";
import { deferred, LOCALES } from "@triliumnext/commons";
import { beforeAll, describe, expect, it } from "vitest";
import becca from "../becca/becca.js";
import branches from "./branches.js";
import cls from "./cls.js";
import hiddenSubtreeService from "./hidden_subtree.js";
import sql_init from "./sql_init.js";
import branches from "./branches.js";
import becca from "../becca/becca.js";
import { deferred, LOCALES } from "@triliumnext/commons";
import { changeLanguage } from "./i18n.js";
import sql_init from "./sql_init.js";
describe("Hidden Subtree", () => {
beforeAll(async () => {

View File

@ -1,6 +1,7 @@
import { LOCALES } from "@triliumnext/commons";
import { readFileSync } from "fs";
import { join } from "path";
import { describe, expect, it } from "vitest";
describe("i18n", () => {
it("translations are valid JSON", () => {

View File

@ -1,3 +1,5 @@
import { describe, expect, it } from "vitest";
import { buildNote } from "../test/becca_easy_mocking";
import { determineBestFontAttachment, generateCss, generateIconRegistry, IconPackManifest, processIconPack } from "./icon_packs";

View File

@ -5,7 +5,7 @@ import dateUtils from "./date_utils.js";
import keyboardActions from "./keyboard_actions.js";
import log from "./log.js";
import optionService from "./options.js";
import { isWindows,randomSecureToken } from "./utils.js";
import { isWindows, randomSecureToken } from "./utils.js";
function initDocumentOptions() {
optionService.createOption("documentId", randomSecureToken(16), false);

View File

@ -1,22 +1,20 @@
import { trimIndentation } from "@triliumnext/commons";
import { beforeEach, describe, expect, it, vi } from "vitest";
import becca from "../becca/becca.js";
import BBranch from "../becca/entities/bbranch.js";
import BNote from "../becca/entities/bnote.js";
import { buildNote } from "../test/becca_easy_mocking.js";
import { note, NoteBuilder } from "../test/becca_mocking.js";
import { NoteBuilder } from "../test/becca_mocking.js";
import cls from "./cls.js";
import { buildJsx, executeBundle, getScriptBundle } from "./script.js";
describe("Script", () => {
let rootNote!: NoteBuilder;
beforeEach(() => {
becca.reset();
rootNote = new NoteBuilder(
new NoteBuilder(
new BNote({
noteId: "root",
title: "root",

View File

@ -1,5 +1,5 @@
import { trimIndentation } from "@triliumnext/commons";
import { describe, expect,it, vi } from "vitest";
import { beforeAll, describe, expect, it, vi } from "vitest";
import { buildShareNote, buildShareNotes } from "../test/shaca_mocking.js";
import { getContent, renderCode, type Result } from "./content_renderer.js";

View File

@ -4,7 +4,7 @@ import ejs from "ejs";
import escapeHtml from "escape-html";
import { readFileSync } from "fs";
import { t } from "i18next";
import { HTMLElement, Options,parse, TextNode } from "node-html-parser";
import { HTMLElement, Options, parse, TextNode } from "node-html-parser";
import { join } from "path";
import becca from "../becca/becca.js";

View File

@ -1,6 +1,7 @@
import { beforeAll, beforeEach, describe, expect, it } from "vitest";
import type { Application, NextFunction,Request, Response } from "express";
import supertest from "supertest";
import type { Application, Request, Response, NextFunction } from "express";
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { safeExtractMessageAndStackFromError } from "../services/utils.js";
let app: Application;

View File

@ -6,9 +6,6 @@
"target": "ES2020",
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]

View File

@ -3,9 +3,6 @@
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]

View File

@ -9,6 +9,7 @@
import { LOCALES } from "./i18n.js";
import { DAYJS_LOADER, dayjs } from "./dayjs.js";
import { describe, expect, it } from "vitest";
describe("dayjs", () => {
it("all dayjs locales are valid", async () => {

View File

@ -1,4 +1,5 @@
import { deferred } from "./utils.js";
import { describe, expect, it } from "vitest";
describe("#deferred", () => {
it("should return a promise", () => {

View File

@ -3,9 +3,6 @@
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
],

View File

@ -8,6 +8,7 @@ import type { Content } from "./Content.js";
import { Stream } from "stream";
import type { Range } from "./Range.js";
import type { MockInstance } from "vitest";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
describe("createPartialContentHandler tests", () => {
let logger: Logger;

View File

@ -1,6 +1,7 @@
import { parseRangeHeader } from "./parseRangeHeader.js";
import type { Logger } from "./Logger.js";
import { RangeParserError } from "./RangeParserError.js";
import { describe, expect, it, vi, afterEach, beforeEach } from "vitest";
describe("parseRangeHeader tests", () => {
let logger: Logger;

View File

@ -1,5 +1,5 @@
import type { Request, Response } from "express";
import { expect, type Mock } from "vitest";
import { beforeEach, describe, expect, it, vi, type Mock } from "vitest";
import {
getHeader,

View File

@ -3,9 +3,6 @@
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
]

View File

@ -3,9 +3,6 @@
"compilerOptions": {
"outDir": "./out-tsc/vitest",
"types": [
"vitest/globals",
"vitest/importMeta",
"vite/client",
"node",
"vitest"
],

13
vitest.config.ts Normal file
View File

@ -0,0 +1,13 @@
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
projects: [
"packages/*/vitest.config.ts",
"packages/*/vite.config.ts",
"apps/*/vitest.config.ts",
"apps/*/vite.config.ts",
"apps/*/vite.config.mts",
],
},
})

View File

@ -1 +0,0 @@
export default ['**/vite.config.{mjs,js,ts,mts}', '**/vitest.config.{mjs,js,ts,mts}'];