Skip to content

Build your personal knowledge base with Trilium Notes

test(standalone): fix some failing tests after merge

Elian Dorane0fa5bc9c85a
diff --git a/apps/server/src/services/data_dir.spec.ts b/apps/server/src/services/data_dir.spec.ts
index 223e17693d..a6a408b269 100644
--- a/apps/server/src/services/data_dir.spec.ts
+++ b/apps/server/src/services/data_dir.spec.ts
@@ -1,8 +1,8 @@
-import { beforeEach, describe, expect, it, vi } from "vitest";
+import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import type { getDataDirs as getDataDirsType, getPlatformAppDataDir as getPlatformAppDataDirType,getTriliumDataDir as getTriliumDataDirType } from "./data_dir.js";
-describe("data_dir.ts unit tests", async () => {
+describe("data_dir.ts unit tests", () => {
let getTriliumDataDir: typeof getTriliumDataDirType;
let getPlatformAppDataDir: typeof getPlatformAppDataDirType;
let getDataDirs: typeof getDataDirsType;
@@ -16,42 +16,45 @@ describe("data_dir.ts unit tests", async () => {
pathJoinMock: vi.fn()
};
- // Reset the module cache so the dynamic imports below get a fresh instance
- // of data_dir.ts with the mocked dependencies rather than the cached copy
- // loaded by spec/setup.ts.
- vi.resetModules();
-
- // using doMock, to avoid hoisting, so that we can use the mockFn object
- // to collect all mocked Fns
- vi.doMock("node:fs", () => {
- return {
- default: {
- existsSync: mockFn.existsSyncMock,
- mkdirSync: mockFn.mkdirSyncMock,
- statSync: mockFn.statSyncMock
- }
- };
- });
+ beforeAll(async () => {
+ // Reset the module cache so the dynamic imports below get a fresh instance
+ // of data_dir.ts with the mocked dependencies rather than the cached copy
+ // loaded by spec/setup.ts. This must run inside beforeAll (not at
+ // describe-level) so that spec/setup.ts's beforeAll completes first.
+ vi.resetModules();
+
+ // using doMock, to avoid hoisting, so that we can use the mockFn object
+ // to collect all mocked Fns
+ vi.doMock("node:fs", () => {
+ return {
+ default: {
+ existsSync: mockFn.existsSyncMock,
+ mkdirSync: mockFn.mkdirSyncMock,
+ statSync: mockFn.statSyncMock
+ }
+ };
+ });
- vi.doMock("node:os", () => {
- return {
- default: {
- homedir: mockFn.osHomedirMock,
- platform: mockFn.osPlatformMock
- }
- };
- });
+ vi.doMock("node:os", () => {
+ return {
+ default: {
+ homedir: mockFn.osHomedirMock,
+ platform: mockFn.osPlatformMock
+ }
+ };
+ });
- vi.doMock("node:path", () => {
- return {
- join: mockFn.pathJoinMock
- };
- });
+ vi.doMock("node:path", () => {
+ return {
+ join: mockFn.pathJoinMock
+ };
+ });
- // import function to test now, after creating the mocks
- ({ getTriliumDataDir } = await import("./data_dir.js"));
- ({ getPlatformAppDataDir } = await import("./data_dir.js"));
- ({ getDataDirs } = await import("./data_dir.js"));
+ // import function to test now, after creating the mocks
+ ({ getTriliumDataDir } = await import("./data_dir.js"));
+ ({ getPlatformAppDataDir } = await import("./data_dir.js"));
+ ({ getDataDirs } = await import("./data_dir.js"));
+ });
// helper to reset call counts
const resetAllMocks = () => {
diff --git a/packages/trilium-core/src/services/script.spec.ts b/packages/trilium-core/src/services/script.spec.ts
index 3002cda888..4e4942d7d8 100644
--- a/packages/trilium-core/src/services/script.spec.ts
+++ b/packages/trilium-core/src/services/script.spec.ts
@@ -42,11 +42,11 @@ describe("Script", () => {
});
vi.mock("./sql_init.js", () => {
- return {
- dbReady: () => {
- console.log("Hello world");
- }
+ const mock = {
+ initializeDb: () => {},
+ dbReady: Promise.resolve()
};
+ return { default: mock, ...mock };
});
});
diff --git a/packages/trilium-core/src/services/tree.spec.ts b/packages/trilium-core/src/services/tree.spec.ts
index d705cba42e..15f55bb794 100644
--- a/packages/trilium-core/src/services/tree.spec.ts
+++ b/packages/trilium-core/src/services/tree.spec.ts
@@ -41,11 +41,11 @@ describe("Tree", () => {
});
vi.mock("./sql_init.js", () => {
- return {
- dbReady: () => {
- console.log("Hello world");
- }
+ const mock = {
+ initializeDb: () => {},
+ dbReady: Promise.resolve()
};
+ return { default: mock, ...mock };
});
});
it("sorts notes by title (base case)", () => {